Jump to content

RegEx help: StringRegExpReplace and Conditional Patterns


Recommended Posts

Don't know if this is possible, but given the example strings:

1A

A

I want to find the string:

(d)?([A-Z])

and if the digit is not present, then i want to add it using StringRegExpReplace. So given the example strings, the result in both cases should be:

1A

This is trivial to do using a method other than StringRegExpReplace, but i want to see if this can be done this way... just because. It seems like the "Conditional patterns" section of the help doc for StringRegExp might hold the key, but i have not been able to get it to work. Here are a couple match patterns i tried:

(d)?(?(1)|1)([A-Z])

(d)?(?(1)$1|1)([A-Z])

(d)?(?(1)g1|1)([A-Z])

And replace pattern is a generic $1$2$3

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

Sorry, the "1" could be anything and the "A" could be anything. I just made the example as simple as i could.

What i'm actually trying to do is find text links in a string and wrap them in HTML to make hyperlinks. So the string could be something like:

go to ex.com but don't go to http://ex2.de or https://ex3.eu

The result needs to be:

go to <a href="ex.com">ex.com</a> but don't go to <a href="http://ex2.de">http://ex2.de</a> or <a href="https://ex3.eu">https://ex3.eu</a>

The problem i'm having with StringRegExpReplace is that, if the https? is present, then the it gets doubled. I need to add it only if it is not present using only StringRegExpReplace. If this can't be done i can do it another way, but i'd like to see if it can.

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

that doesn't prefix the string with "http" if it's missing, so it is not a valid hyperlink :)

in order to do this with only StringRegExpReplace, i am pretty sure the "Conditional patterns" for StrinRegExp needs to be utilized

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

it's just an assumption

if you run across text like example.com within an article or whatever, http will likely work

FUNCTIONS: WinDock (dock window to screen edge) | EditCtrl_ToggleLineWrap (line/word wrap for AU3 edit control) | SendEX (yet another alternative to Send( ) ) | Spell Checker (Hunspell wrapper) | SentenceCase (capitalize first letter of sentences)

CODE SNIPPITS: Dynamic tab width (set tab control width according to window width)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...