Capturing a string until the first carriage character appears in the regex?

I am working with legacy systems at the moment and most of the work is related to decomposing delimited strings and validating certain rules.

With this line, how can I return "Active" in the backlink and search terms, stopping when it hits the first caret (^):

Active^20080505^900^LT^100

      

Can this be done by including this " (.+)

" in the regular expression ? The reason I am asking is because the actual regex is " (.+)

" defined in the database as cutting these messages and their associated rules can be set from an external system. In this case, the content can be anything ("Active"), so in this case ". +" Is used.

Rule. The carriage character cannot be enclosed between parentheses, as this could result in it being stored in a database field and defined elsewhere in a different system field.

If you have a better offer than " (.+)

", he'll be glad to hear it.

Thanks in advance.

0


source to share


3 answers


(.+?)\^

      

Must capture before the first ^

If you need to enable it (.+)

unchanged, you can use this:



(.+?)\^(.+)

      

The first backlink will still be correct, and you can ignore the second.

+5


source


The regex is really overloaded here.

Just take the first n characters of the string, where n is the first carriage position.



Pseudocode:

InputString.Left(InputString.IndexOf("^"))

      

+1


source


^([^\^]+)

      

This should work if your RE library does not support non-greed.

0


source







All Articles