简体   繁体   中英

regex expression to find words with 0

Please provide a regex expression to find words with 0 like 'A0lytics', 'Alter0tive Medicine'. But, it should not match words like 'Enterprise 2.0'

If you have this list of words: ["A0lytics", "0tics", "Alter0tive Medicine", "Enterprise 2.0"]

  • \\w+0\\w+ will capture "A0lytics" and "Alter0tive" (not "Alter0tive Medicine")
  • ^[A-Za-z][A-Za-z0]+(?: +[A-Za-z][A-Za-z0]+)*$ will match "A0lytics" and "Alter0tive Medicine"
  • (?<!\\.)([a-zA-Z]*)0([a-zA-Z]*) will match "A0lytics", "0tics" and "Alter0tive Medicine" (if you can use the negative lookbehind).

Good luck.

You can use:

^[A-Za-z][A-Za-z0]+(?: +[A-Za-z][A-Za-z0]+)*$

Demo: https://regex101.com/r/gJ5ugU/2

\w+0\w+

is it useful? You can test online regular expressions with this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM