01-10-2025 03:10 PM - edited 01-10-2025 03:11 PM
Dear Community
I notice that on a replacement string \. or . ,both work the same.
For example:
Regex expression: (.*)@nono\.com
I can use replacement string: 1234@yesyes\.com OR 1234@yesyes.com
both will lead to same results.
If initial string is 1234@nono.com, both replacement strings with lead to 1234@yesyes.com
Any idea why?
01-10-2025 11:17 PM - edited 01-11-2025 04:30 AM
A dot in Regex means any one character and since the dot is a character then it matches that in your replace that doesn’t have the escape character \ in front of the dot. If you want to be sure it would match only the literal string with the dot exactly in that position I would recommend you to use the match statement that has the escape character so that it literally matches a dot and nothing else.
01-11-2025 06:45 AM - edited 01-11-2025 06:59 AM
Hey Roger
Thank you for your answer.
I am not taking about the regex pattern: i am taking about the replacement string that is configure after a regex is matched. i get the behavior of \. and . on the regex pattern. (Pic attached)
In a nutshell replace string 1234@yesyes\.com and 1234@yesyes.com both have same results. And they are clearly not the same.
i think the correct one should be \., because it is a regular expression that is the literal " ." If we use " ." , it means to replace for any character, and will not make sense (to me). Thats why i was surprise that , in practice, both do the same when use on Replace string.
01-11-2025 07:12 AM
I’m afraid that you lost me, I’m not really grasping your question. Hopefully someone else in the community will.
01-11-2025 07:18 AM
Hey Roger
Look to Replace string in both of my examples. One is 1234@yesyes\.com and the other is 1234@yesyes.com . But both create same end result. Why?
Alex
01-11-2025 07:25 AM
In my view I already have explained that, but you seem to disagree. It’s irrelevant that I explained it from the match perspective, it operates in the same way on both sides.
01-11-2025 07:34 AM - edited 01-11-2025 07:39 AM
Hi Roger
Stay with me here.
You said "A dot in Regex means" but the dot i am referring to is on the Replace string as it is shown in the picture. Replace string can use regular expression (like \n) to reference back to Regex string but in this case there is no \n pattern. To where dot reference to when used on the replace string?
I do understand what the dot on Regex string reference to and how can be use.
Alex
01-11-2025 07:41 AM
Again in my view I’ve provided how I think this works. But as you see it differently I don’t know what I should do to make it across in a way that you feel is appropriate.
01-11-2025 07:44 AM - edited 01-11-2025 07:45 AM
Hey Roger
Thank you for your responses anyways!
Will continue looking around
Have a nice weekend
Alex
01-11-2025 07:51 AM - edited 01-13-2025 01:41 AM
Maybe this could make my point come across. Both the strings, Pattern String (Match) and Replace String operate with Regex.
Hopefully that helps.
01-11-2025 08:08 AM - edited 01-11-2025 08:11 AM
Hey Roger
I get that. The point is: What a regular expression reference back when use on pattern string or on replace string?.
To be more precise i am using the naming that Expressway uses on a testing rule.
A regular expression on a Pattern String reference back to an Alias pattern and on a Replace String reference back to a pattern on a Pattern String.
On this example, When you enter (.*) on pattern string you are reference something on the Alias (in this case 1234). If you enter \1 on the Replace String you are referencing back to a (...) on a Pattern string (that also could reference back to something on Alias).
In this case my question is where dot on replace string reference back on Pattern String.
Alex.
01-11-2025 08:36 AM
I think you’re overthinking this and make it more complicated than it is.
01-15-2025 07:21 PM
As @Roger Kallberg has said, in Regex, just a straight "." refers to any standard ASCII character, whereas a "\." refers specifically to the dot character. So a match for a "." will match anything, including the dot (ie, it will also match, from your example, 1234@yesyesXcom). If you want to match only with 1234@yesyes.com then you should use the \. in the pattern to enforce that character between yesyes and com is a dot and not any other character. The replace string does not need a "." to be escaped with the "\" as the pattern string does, as it is a 1 for 1 replacement. You shouldn't be using a "\" in a replacement string, unless you want to include a result from a previous match, ie the \1, \2, \3, etc will be anything that is included within brackets in the pattern string (a group construct), in the order the brackets appear if there are multiple groups. Noting that none of your screenshot examples include such a thing, so none of your replacements should include a "\".
If you want to play around and test Regex and check results of matches, the regex101: build, test, and debug regex site is a good one to use.
Please remember to mark helpful responses and to set your question as answered if appropriate.
01-16-2025 05:00 AM
Hey Wayne
What i am looking is \dot on the replacement string and not on the pattern matching string. Indeed \dot can be use on the replacement string (you can test it on expressway).
Searching and asking around i found the answer to my own question here:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/substitutions-in-regular-expressions
"The replacement pattern can consist of one or more substitutions along with literal characters".
Meaning that on a replacement string you can use replacement patterns (\1,\2,\3) and literals (like 'a','b','c' etc) and you can NOT use (.*) or d{3} as regular expressions.
Since on replacemnet string you can use ONLY replacement patterns and literals and \dot is not a replacement pattern, \dot is also a literal (the literal dot). Then \dot = dot on replacement pattern but \dot <> dot on matching pattern.
Thats solves the mystery!
Thanks for your answer.
Alex
01-11-2025 07:09 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide