Regex Question

Hi,

I want to replace using this regex pattern “[^a-zA-Z]” to remove anything that isn’t a letter.

dim rx as new RegEx rx.SearchPattern ="[^a-zA-Z]" dim match as RegExMatch = rx.Search(TextField1.Text ) if match is nil then msgbox "nothing found" else msgbox "found it" rx.ReplacementPattern="[^a-zA-Z]" end if

but it wont work.
its mention in LR. that I have to use. regex.replace, but that option is not showing.

any help. ?

thanks
regards,
arief

Something like this…

[code]dim s as string=“abc123ABC!@#”

dim rx As new RegEx
rx.Options.ReplaceAllMatches=true
rx.SearchPattern="[^a-zA-Z]"
rx.ReplacementPattern=""

s=rx.Replace(s)
[/code]

thanks,

it works…

regards,
arief

A couple of things about your pattern:

  • Xojo’s RegEx is case-INsensitive, so you only need [^a-z].
  • If the text you’re matching against might contains letters from other languages than English, e.g., “ü”, you are better off using the Unicode variant. Try \\PL instead, which means “anything that is not a letter as defined by Unicode”.