0

I have data like the following

4  #VS   7 J9 C9 D9 I9 Z0 W8 S6 H0 LHRLAX 1115 1435      346 0E
5  $UN7107 J4 C4 D4 S. Y4 H4 Q4 B4 LHRLAX 1115 1435   *  744 0E

To get the data, I have the following regex

\A(\d)+[^#$]*?\#(?'code1'\p{Lu}{2})\s*(?'code2'\d{1,4})\b\s*(?<seat1>[A-Z][0-9.](?:\s+[A-Z][0-9.])*+)\s+(?<from>[A-Z]{3})(?<to>[A-Z]{3})\s+(?<other>.*\S)\s*

Now this works perfectly for the first line, but for the second line, the flight number starts with a $ instead of a # and I cant seem to match it. I have added a $ to the regex string without success.

How can I get this working?

Thanks

0

1 Answer 1

2

\A matches start of string while you apparently want to match start of line with ^, and you also need to match both # and $ while your [^#$]*? was only matching "anything until one of those characters":

^(\d)+\s*[#$](?'code1'\p{Lu}{2})\s*(?'code2'\d{1,4})\b\s*(?<seat1>[A-Z][0-9.](?:\s+[A-Z][0-9.])*+)\s+(?<from>[A-Z]{3})(?<to>[A-Z]{3})\s+(?<other>.*\S)\s*

online test

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.