Regex: how to determine odd/even number of occurrences of a char preceding a given char? -


I | Terms like with or will be changed to uncompressed only, such as:

  "this | he" | | "Other |" - & gt; "This | that" or "other"  

Yes, I can split on space or dialect, find an array and repeat through it, and rebuild the string I guess, but it seems ... fool, it is possible that there is a regex way to do this by counting " before " and obviously strange means < Code> | is cited and even this does not mean. (Note: Processing does not start Unless there is not a single number of ", if at least one is " ).

itemprop = "text">

It is true that regexes can count, but they can be used to determine if something strange or even something The number is the trick to be done in this case, it is to quote the quotation marks after that the pipes, not before.

  str = str.replace (/ \ | (? = (?: (?: [^ "] *") {2}) * [^ "] * $) / g," or "); By breaking that down,  (?: [^ "] *]" {2}  matches the next pair of quotes if there is one Non-quotes in the middle After you do this, as often as possible (which can be zero),  [^ "] * $  consumes the remaining non-quotes by the end of the string. 

< P> Definitely, it is assumed that the text is very well formed. It does not solve the problem of quotes escaping, but it can be done when you need it.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -