Hello!
How can i use "RegExpSubstitute" to ask for exact match of a string containing only 3 characters like "C:\"
MeasureName=DiskName
IfMacht=C:\ | D:\ | E:\
IfMachtAction=[DoSomting]
It is currently April 26th, 2024, 4:33 pm
IfMatch with special characters
-
- Posts: 98
- Joined: August 31st, 2022, 10:00 pm
-
- Developer
- Posts: 22630
- Joined: April 19th, 2009, 11:02 pm
- Location: Fort Hunt, Virginia, USA
Re: IfMatch with special characters
The "\" character is a reserved character in Regular Expression. It means "escape the next character and treat it as a literal rather than a reserved character." So to specify a literal "\" in a search parameter, you have to "escape" it, like this:Jaime Méndez wrote: ↑October 31st, 2022, 5:15 pm Hello!
How can i use "RegExpSubstitute" to ask for exact match of a string containing only 3 characters like "C:\"
MeasureName=DiskName
IfMacht=C:\ | D:\ | E:\
IfMachtAction=[DoSomting]
Code: Select all
IfMatch=C:\\|D:\\|E:\\
IfMatchAction=[!Log "Yessir, that's my baby. Nosir, I don't mean maybe"]
-
- Rainmeter Sage
- Posts: 5407
- Joined: April 12th, 2012, 9:40 pm
- Location: Cedar Point, Ohio, USA
Re: IfMatch with special characters
JSMorely beat me but I will leave my suggestions...
The string you are testing contains a reserved character \ (backslash) so you need to either "escape" that with another backslash or use :EscapeRegExp section variable.
This code manually escapes the backslash and disregards string case. (?i) will match any drive letter defined regardless of the string case.
This code automatically escapes reserved characters and disregards string case. (?i) will match any drive letter defined regardless of the string case.
Notice DynamicVariables=1 must be used with section variables.
That's not RegExpSubstitute, you posted an IfMatch RegExpression test... but that is not important.Jaime Méndez wrote: ↑October 31st, 2022, 5:15 pm Hello!
How can i use "RegExpSubstitute" to ask for exact match of a string containing only 3 characters like "C:\"
MeasureName=DiskName
IfMacht=C:\ | D:\ | E:\
IfMachtAction=[DoSomting]
The string you are testing contains a reserved character \ (backslash) so you need to either "escape" that with another backslash or use :EscapeRegExp section variable.
This code manually escapes the backslash and disregards string case. (?i) will match any drive letter defined regardless of the string case.
Code: Select all
[MeasureDiskName]
Measure=String
String=[DiskName]
IfMatch=(?i)C:\\|D:\\|E:\\
IfMachtAction=[DoSomething]
Code: Select all
[MeasureDiskName]
Measure=String
String=[DiskName:EscapeRegExp]
IfMatch=(?i)C:\|D:\|E:\
IfMachtAction=[DoSomething]
DynamicVariables=1
:: My DA Gallery :: Rainmeter DA Gallery :: Rainmeter Workshops :: Rainmeter Documentation :: BBCode Guide ::
-
- Posts: 98
- Joined: August 31st, 2022, 10:00 pm
Re: IfMatch with special characters
Thank you both! It was easer than i thoughteclectic-tech wrote: ↑October 31st, 2022, 6:27 pm This code manually escapes the backslash and disregards string case. (?i) will match any drive letter defined regardless of the string case.Code: Select all
[MeasureDiskName] Measure=String String=[DiskName] IfMatch=(?i)C:\\|D:\\|E:\\ IfMachtAction=[DoSomething]