ChrisAdmin
ChrisAdmin

Reputation: 1002

Trying to limit a RegEx to With or Without a space, including a '-' without spanning more than 2 words

Thankyou in advance, complete noob at regular expressions here!

I'm searching HTML for a model number, for example. "ER-A320"

Which can be expressed on a webpage as "ERA320", "ER A320" or "ER-A320"

I've got stuck at about this:

ER(\s*|.*)A320

I know this is completely wrong, the above expression isn't limited to 1 space, it will span a whole line unfortunately. e.g. "ER all the way to A320"

And won't pick up no-space e.g. "ERA320"

And addes a nasty '-' sign to the end.

Thanks

Upvotes: 0

Views: 113

Answers (2)

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104721

I don't know exactly what you're looking for, are you looking for this exact model "ERA320" or "aaa000".

If you're looking for a pattern, use this:
[A-Z]{2}[\s|\-]?A[0-9]{3}, assuming you're looking for "XXANNN", X means A-Z, A means A and N is a number.

Otherwise use this:
ER[\s-]?A320.

Upvotes: 0

Aurelio De Rosa
Aurelio De Rosa

Reputation: 22152

This regular expression should work:

ER[ -]?A320

Upvotes: 1

Related Questions