0

Needle in haystack: Specific string followed by exact set of numbers

How can I search for ABC???? where ABC should be exactly that, but the ???? must be exactly four numbers, ideally followed by whitespace.

Illustrative examples:

  • LHRJFKABC1234 233 <-- Has needle
  • EABC123 LHRJFK <-- Does not have needle as only 3 numbers following ABC

Something tells me I need to search for string + something like (\d{4}) for the 4 numbers. But not sure quite how to puzzle it all together.

What I've found so far:

1 Answer 1

1

For things like this I find an online checker like Rubular very handy.

Unless I'm misunderstanding, the regex ABC\d{4}\s should work for you. Do you need groupings (i.e. to match the 4-digit part)?

Try it out on Rubular here

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.