Advertisement
here2share

RegEx -- String Dismissal

Nov 20th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. RegEx -- String Dismissal
  2.  
  3. If you want to match a word A in a string and not to match a word B. For example: If you have a text:
  4.  
  5. 1. I have 3 pets - 2 dogs and a cat
  6. 2. I have 1 pet - a dog
  7.  
  8.  
  9. If you want to search for lines of text that HAVE a dog for a pet and DOESN'T have cat you can use this regular expression:
  10.  
  11. ^(?=.*?\bdog\b)((?!cat).)*$
  12.  
  13.  
  14. It will find only second line:
  15.  
  16. 2. I have 1 pet - a dog
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement