I am using regular expressions to create a simple JavaScript application. I've looked at some answers here from the community, and unfortunately I'm still unable to create a regular expression that suits my specific case. I apologize, but I have no mastery over regular expressions.
I wish I could solve my problem without using a reverse function, or any utility function if possible. If this can only be solved with one, then that's fine, there's nothing to be done.
THE PROBLEM
Consider the following text (it's in portuguese, Brazil, so accented characters need to be considered, like Álvares, Ligações, América, etc.):
O Brasil é um país com muitos brasileiros. Alguns dizem Abrasil, outros nem tanto.
What I seek:
"Brasil" true // Desired result
" Brasil" false
"brasil"eiros false
A"brasil" false
The regular expression currently used (not correct):
([^\w|^\u0080-\u00FF])(Brasil)(?![\w|\u0080-\u00FF])
The part of the expression I'm having trouble with:
([^\w|^\u0080-\u00FF])
The (wrong) result I am getting at the moment:
" Brasil" // I just want "Brasil"
Bibliography
- javascript regex - look behind alternative?
- utf-8 word boundary regex in javascript
- Javascript: negative lookbehind equivalent?
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Even accepted, from what I could see, look behind is not yet widely implemented.