Sunday, 15 June 2014

Need a RegEx that matches only a single instance of the pipe character -



Need a RegEx that matches only a single instance of the pipe character -

i'm trying write regex match instances of 'pipe' character (|) not followed 1 or more farther pipes. pipe followed other pipe.

i have doesn't appear working:

/|(?!/|)

you escaping pipe wrongly. need utilize backslash, , not slash. apart that, need utilize negative look-behind, last pipe not matched, not preceded pipe, not followed it: -

(?<!\|)\|(?!\|)

generally, prefer utilize character class rather escaping if want match regex meta-character class: -

(?<![|])[|](?![|])

but, it's taste.

regex

No comments:

Post a Comment