Regex to select specific stretch

Asked

Viewed 1,054 times

8

I need to identify within contracts the name information, CPF and address.

The landlord’s line is as follows:

LESSOR: Jose Reinaldo Lellis de Andrade

RENTAL COMPANY: Isabel Cristina de Rezende Leme Ferreira Andrade

I can select the entire line through the code (locador[a]?):.*\n, but this expression returns me the word Lessor too.

How do I return only the name after the word LOCADOR/LOCADORA:?

  • 4

    Each technology has its own way of designating and naming groups in regular expressions. If I can provide you with what technology you’re using, I can improve my response.

  • which language? many languages have peculiarities as to their regex implementations

3 answers

3

As stated in the other answer you must specify which technology you are using.

The regex below is running on a test I performed:

/locador..(.*)/gi 

Demo

  • Great that regex101

2

(locador[a]?):(.*)\n

I don’t know what technology you’re using, but basically you’d have to take the name of the second group (second set in parentheses) and delete the \n of the end.

  • 1

    Why not simplify to locadora?:(.*)\n?

  • He wants "landlord" and "rental". I’ll put the \n in the end.

  • 2

    In locadora?, the ? applies only to a. But anyway.. It makes no difference, it’s just to save characters. The way you wrote maybe it’s more readable even.

  • You’re right. I usually use the most didactic way in the answers. In this case I’ll leave it at that.

0

The answer of stderr is correct but only to clarify the error of your Regex It was the use of parentheses they that separate the match group, ie what you want to capture

locador[a]?:(.*)

https://regex101.com/r/mP0bC2/2

Browser other questions tagged

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