Regex help

Hi,

I have string contain “_” (underscore sign).

does anyone knows how to put it as regex pattern ?

thanks
Arief

What do you want to match? What should be found?

I am looking for every string from a listbox contains underscore sign.
if its exist then I want to rename it into plus sign.

thanks
arief

[code]dim rx as new RegEx
rx.SearchPattern = “(?mi-Us)_”
rx.ReplacementPattern = “+”

dim rxOptions as RegExOptions = rx.Options
rxOptions.LineEndType = 4
rxOptions.ReplaceAllMatches = true

dim replacedText as string = rx.Replace( sourceText )[/code]

I put a textfield on it, when I do type the “_” ,its does not change the sign.
what if the name has a prefix like,

A_
B_
C_

[code] dim rx as new RegEx
rx.SearchPattern = “(?mi-Us)_”
rx.ReplacementPattern = “+”

dim rxOptions as RegExOptions = rx.Options
rxOptions.LineEndType = 4
rxOptions.ReplaceAllMatches = true

dim replacedText as string = rx.Replace( textfield1.text )[/code]

thanks
Arief

Add TextField.TextChange Event:

[code] dim rx as new RegEx
rx.SearchPattern = “(?mi-Us)_”
rx.ReplacementPattern = “+”

dim rxOptions as RegExOptions = rx.Options
rxOptions.LineEndType = 4
rxOptions.ReplaceAllMatches = true

dim replacedText as string = rx.Replace( textfield1.text )
textfield1.text = replacedText[/code]
But why not simple use this:

TextField1.Text = TextField1.Text.ReplaceAll("_", "+")

Yes, its worked, thanks.

[quote]But why not simple use this:

TextField1.Text = TextField1.Text.ReplaceAll("_", “+”)[/quote]

I have another goals,

What I am trying to do is, I listed all the file in a folder with generated filename + date+hour+minute, separated by “-” (name_date+hour+minute) into a listbox.

name_201809030956
name_201809030957
name_201809030958

so, when I do searching the file using getfolderitem, once the file is exist, delete it and change the sign into “+”
so, its easy to recognize it.

Thanks
Arief

then you should use another regex pattern
one that detects any letter from any length, then an underscore, and then a suite of 12 numbers.
to detect your files.
then replace _ with + only on these files.

Hi Mr. Pochez,

Yes, it has to be done by using another regex pattern. I was trying harder, but still found no logic to do it, because its has random number in the filename. I don’t know to combine it with folderitem method.

If there’s any sample and help would be great…

thanks
arief

The pattern would’ve something like

([^_]+_[0-9]{12,12})

But you would still have to iterate over each file in the directory yourself and check each name.