Skip to main content
Perl prefers $ in replacement phase of captured items.
Source Link

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[\2][$2](\1$1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads &and prints file line by line – like sed does.

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used to work around this

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads & prints file line by line – like sed does

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used to work around this

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[$2]($1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads and prints file line by line – like sed does.

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used to work around this
deleted 5 characters in body
Source Link
guest
  • 2.2k
  • 6
  • 11

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads & prints file line by line, like sed does

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used above to work around this

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads & prints file line by line, like sed does

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used above to work around this

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads & prints file line by line like sed does

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used to work around this
Source Link
guest
  • 2.2k
  • 6
  • 11

sed uses basic and extended regular expressions (BRE/ERE). .*? is part of a Perl Compatible Regular Expression (PCRE).

To use PCRE, use perl:

$ perl -pe 's/<a.*?href="(.*?)".*?>(.*?)<\/a>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • This is exactly the same expression as the original, but used with perl -p which reads & prints file line by line, like sed does

Here is a similar regex using ERE with sed:

$ sed -E 's/<a[^>]*href="([^"]*)[^>]*>([^<]*)[^>]*>/[\2](\1)/g' test
on [reddit](https://www.reddit.com/) or [Lifehacker](https://lifehacker.com/)
  • PCRE uses a ? following a quantifier to match the shortest repetition, standard regular expressions do not
  • Negated character classes are used above to work around this