Regular expression that returns next words

Asked

Viewed 83 times

0

Well I’m working on a regular expression that picks up license plates, my interest would be not just picking up the license plates, but like things next to it, for example:

|Placa:AVX-4300 Fiat Uno |     

Here’s the expression I’m using [A-Z]{3}-[0-9]{4}, who can help me.

  • What is the format of the text you will run regex in? All are in this format: |Board:AVX-4300 Fiat Uno |?

  • yes, they are all in the shape of a single line, I wanted to delimit the number of next words that he picks up.

  • But do all lines follow a defined format? If not, they will not be regular and therefore regex is not a solution. If so, what exactly is the format? You will always have the make and name of the vehicle?

  • You’ll always have yes.

1 answer

1

You can use this regex:

[A-Z]{3}-[0-9]{4}\s\w+\s\w+

I just added \s\w+\s\w+ which will capture next to the board plus two strings (containing letters, numbers or underscore) consecutive separated by space (\s).

If you want to include a hyphen in the search, it would be:

[A-Z]{3}-[0-9]{4}\s[\w-]+\s[\w-]+

Check it out at Ideone

  • But the \w already takes letters and numbers.

  • no problem to take letters and numbers, ta bom po.

  • how would I look to catch before tbm

  • Before the plate number? Can you give an example?

  • alter \s[\w-]+\s[\w-]+ for ((?:\s[\w-]+)*), so you create a group just for this information, in addition to leaving optional and unlimited, as many words as needed. See in REGEX101

  • @Guilhermelautert In Python returns only "Fiat Uno "

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.