C# regex to find all spaces which are not behind a specified word -


i'm having trouble create .net-regex finds spaces not behind word pi.

this given string "y + pi + s + 1 = x"

i tried "(?!pi\s)\s" finds every space , didn't exclude 1 after "pi". used .net regey tester

any appreciated

the issue regex it's looking double-space*: \s in look-behind makes "a space preceded 'p', 'i', '', not space preceded 'p', 'i'

the fix straightforward - remove \s lookbehind:

(?<!pi)\s 

note regex skip spaces preceded longer words ending in pi well, such principi. if not want these matches, add \b in front of pi:

(?<!\bpi)\s 

* note syntax lookbehind wasn't correct because of missing <. assume typo.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -