I need a way to remove the “U.” part of the string only when “. U.” or “.U.” are at the end of the string itself (1st case is with a space and the 2nd without it).
- Que tiene amistad.U.
- Que tiene amistad. U.
- Im fan of U. of Chicago.
- Im fan of the Knicks. U. of Chicago.
From these 4 strings, it should only be applied to 1 and 2. So the resulting texts in each case would be:
- Que tiene amistad.
- Que tiene amistad.
- Im fan of U. of Chicago.
- Im fan of the Knicks. U. of Chicago.
I tried several alternatives with str_replace(), but this has to be done with regex because of the conditions bosted above. Any ideas? Thanks!
I’m answering this way too often, but a “lookbehind” assertion might work here:
That leaves dot and/or trailing space in, only looks at them as condition.