c# - How to construct a regex to match a fixed string separated by whitespace? -


i've never been able construct regular expression on own, , have simple application needs one. how construct simple regex matches:

  1. a fixed string
  2. no whitespace / whitespace
  3. the '=' char
  4. no whitespace / whitespace
  5. the '(' char

currently i'm using following code match whole words, can see quite limited in functionality.

regex.matches(data, @"\b" + regex.escape(columnid + "=(") + @"\b"); regex.matches(data, @"\b" + regex.escape(columnid + "= (") + @"\b"); regex.matches(data, @"\b" + regex.escape(columnid + " =(") + @"\b"); regex.matches(data, @"\b" + regex.escape(columnid + " = (") + @"\b"); 

“any” in regex means * quantifier (“kleene star”), means “the previous token, arbitrarily often”.

note work can escape only fixed word, not rest.

regex.matches(data, @"\b" + regex.escape(columnid) + @" *= *\(\b"); 

also note had escape opening parenthesis @ end hand.

and, hans noted correctly in comments, it’s common use \s instead of space ; \s stands “whitespace”, includes conventional spaces, tabs , newline characters.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -