Remove specific words from csv string containing specific word
I have meta keywords exported to csv file
Example:
For Rent ABC-1234 , For Rent ABC-1234 Rental, For Rent ABC1234 , For Rent ABC1234 Rental, For Rent ABC 1234 , For Rent ABC 1234 Rental, For Lease ABC-1234 , For Lease ABC-1234 Rental, For Lease ABC1234 , For Lease ABC1234 Rental, For Lease ABC 1234 , For Lease ABC 1234 Rental
What I would like to do is values that read "Rent XXX Rent" to remove "Rent" from those values, so the remaining value would just read "XXX Rental".
Is this possible with regex?
source to share
You can use this regex in "Find" in the field:
For Rent ([^,]+ Rental)
Replace
$1
[^,]
means "any character, but a comma, +
- 1 or more times. I see the values are comma separated, so this seems like a safe pattern. For a safer match, you can try For Rent ([^,]*? +Rental)
in the Find box (this will also take into account multiple spaces before Rental
).
Output:
For Rent ABC-1234 , ABC-1234 Rental, For Rent ABC1234 , ABC1234 Rental, For Rent ABC 1234 , ABC 1234 Rental, For Lease ABC-1234 , For Lease ABC-1234 Rental, For Lease ABC1234 , For Lease ABC1234 Rental, For Lease ABC 1234 , For Lease ABC 1234 Rental
source to share
I think this is what you want:
(A[^,]+\d Rental)
This will select "xxx Rental" from "Rent / Rent xxx Rent" and you don't need to replace anything.
EDIT:
The above works if the i
(case insensitive) flag is not enabled.
For a case insensitive regex, use the following instead:
(?<=\w{4}\s|\w{5}\s)([^,]+\d Rental)
-
(?<=\w{4}\s|\w{5}\s)
is a positive look and feel of the template that matches the lines followed by\w{4}\s
(rent) or\w{5}\s
(rent).
For \w+ \K([^,]+\d Rental)
-
\K
discards all previous matches and starts matching the current position.
source to share