regular expression, non-greedy *

Discussion in 'Programming' started by blueraincap, Jan 26, 2018.

  1. I have a file with a tons of links of 2 formats as follows:

    A. <a href="" target="_blank">Doggy</a>

    B. <a href="">Catty</a>

    I want to search those links of type B, but don't know how.
    <a href="http.*?"> identifies both A and B as the * searches all the way, but I want the * to last until it encounters "
  2. Simples


    blueraincap likes this.
  3. <a href="htt[^"][^"]*?"> This does work to nail down the type B links.

    Now, if I wanna add [target="_blank"] to the back of those B links, Find and Replace will simply paste the regex, how should that be done?
  4. Simples


    Depends on the language. With regex you could use parameters to catch the string, if your library supports it. You could also catch the substring index/length and use some Mid function to get the string.

    A very simple solution if you don't want to program it would be to use sed to preprocess. Sed can extract and transform most simple cases.
  5. Right, I didn't know the $1, $2, $3 to represent (group 1) ...
  6. Baron

    Baron ET Founder

    Are you just trying to make all the B links have target="_blank" in them like the A links?