Skip to main content
Fixed wrong answer; added image and correct answer with more clarity
Source Link
Thinkr
  • 3.8k
  • 3
  • 13
  • 45

The expression thatIf I understood well, you provided (\b\w+\b(?=\.)) matcheswant to return any word that is immediately followed by a dot in a given string. In the example you provided, the function Reg.Extract("123. xpto.", \b\w+\b(?=\.),1)

REGEX.EXTRACT(“123. xpto.”, `\b\w+\b(?=\.)`,1)

should return the word "xpto" because it immediately follows the dot in"The formula contains a syntax error", since the stringRegex's syntax is incorrect.

If you want to modify the regular expression so that it also captures the word immediately before the dot, you can use a slightly different expressionHere is how your Regex parameter should look like: (\b\w+\b)\. (Here, theAdding parentheses around \b\w+\b create a capturing group that includesmake it capture the entire word immediately beforebefore the perioddot. You also need to encapsulate the Regex with double quotes (no single quotes or tildes).

So theThe modified function would look like this: Reg.Extract("123. xpto.", "(\b\w+\b)\.", 1). It

Regex.Extract("123. xpto.", "(\b\w+\b)\.", 1)

And it should return the words "123" and "xpto""123."

enter image description here

The expression that you provided (\b\w+\b(?=\.)) matches any word that is immediately followed by a dot in a given string. In the example you provided, the function Reg.Extract("123. xpto.", \b\w+\b(?=\.),1) should return the word "xpto" because it immediately follows the dot in the string.

If you want to modify the regular expression so that it also captures the word immediately before the dot, you can use a slightly different expression: (\b\w+\b)\. (Here, the parentheses around \b\w+\b create a capturing group that includes the entire word immediately before the period).

So the modified function would look like this: Reg.Extract("123. xpto.", "(\b\w+\b)\.", 1). It should return the words "123" and "xpto".

If I understood well, you want to return any word that is immediately followed by a dot in a given string. In the example you provided, the function

REGEX.EXTRACT(“123. xpto.”, `\b\w+\b(?=\.)`,1)

should return "The formula contains a syntax error", since the Regex's syntax is incorrect.

Here is how your Regex parameter should look like: (\b\w+\b)\. Adding parentheses around \b\w+\b make it capture the entire word before the dot. You also need to encapsulate the Regex with double quotes (no single quotes or tildes).

The modified function would look like this:

Regex.Extract("123. xpto.", "(\b\w+\b)\.", 1)

And it should return "123."

enter image description here

Source Link
Thinkr
  • 3.8k
  • 3
  • 13
  • 45

The expression that you provided (\b\w+\b(?=\.)) matches any word that is immediately followed by a dot in a given string. In the example you provided, the function Reg.Extract("123. xpto.", \b\w+\b(?=\.),1) should return the word "xpto" because it immediately follows the dot in the string.

If you want to modify the regular expression so that it also captures the word immediately before the dot, you can use a slightly different expression: (\b\w+\b)\. (Here, the parentheses around \b\w+\b create a capturing group that includes the entire word immediately before the period).

So the modified function would look like this: Reg.Extract("123. xpto.", "(\b\w+\b)\.", 1). It should return the words "123" and "xpto".