Question

Im trying to extract an address (written in french) out of a listing using regex. here is the example:

"Don't wait, this home won't be on the market for long! Pictures can be forwarded upon request.

123 de la street - city 345-555-1234 "

Imagine that whole thing is item.description. Here is a working set so far:

In "item.description", replace "^\d{1,4} des|de la|du [^,\s]+$" with "whatever"

and the address (123 de la street) will be correctly written over with whatever. BUT if I try to make it the only thing kept from the description, something like this (which dosent work):

In "item.description" replace "(.)(^\d{1,4} des|de la|du [^,\s]+$)(.)" with "$2"

What would be the best way to replace the whole description with just the address?

Thanks!

Was it helpful?

Solution

Try adding * to the first and last token, plus watch out for ^$ signs! (They match start and end of the text.)

"^(.*)(\d{1,4} des|de la|du [^,\s]+)(.*)$"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top