8

Could someone tell me if it's possible to use a regex expression to convert a url to lowercase?

This is within a html img tag so we could find the urls by tag.

Here is an example of what i have

<img src="http://www.domain.com/dir/dir/ImageName.jpg" />

And i need to lowercase the image name at the end.

<img src="http://www.domain.com/dir/dir/imagename.jpg" />

The document contains furhter HTML so i cannot simply lowercase the entire document.

0

3 Answers 3

15

Use the following as a search term:

("http[^"]*")

and replace it with this:

\L\1
2
  • Top work sir, that works exactly as i needed. Thank you very much :) Commented Jun 12, 2013 at 19:45
  • 1
    dont forget if replacing more that you follow the to-lower with \E! \L\1\E otherwise \L\1" some OTHER text OTHER will be other!
    – Hashbrown
    Commented Mar 19, 2020 at 8:30
2

This regular Expression should work to find the URL with capital letters:

(http.*[A-Z].*\.[a-zA-Z]{2,4})

Note that you do need to check the "Match case" option

Under "Replace with" use

\L\1

How it works:

The parentheses mean you are going to store the result found with what is between them. In this case the whole thing is stored in \1

We then start by looking for http followed by anything (.*) until a capital letter [A-Z]. Then more anything until a period followed by 2-4 letters (\.[a-zA-Z]{2,4})

If you have further questions, leave a comment.

2
  • This seems to overrun and selects more than just the src tag. However, ctn's suggestion has worked spot on for my. Thank you for your time and input though. I appreciate it. Commented Jun 12, 2013 at 19:45
  • Un-check ". matches newline" Commented Jun 12, 2013 at 19:49
0

For me, to convert upper case letters in links to lower case then :

(http.[A-Z]..[a-zA-Z]{2,4})

worked as a regex in Text Crawler free (ver. 3.0.3) to find 2,238 links in a large file of mine, as does "http[s]?://.+?"

Though (courtesy of Stefan from Grepwin) the pattern of :

((http|https)://([\w_-]+(?:(?:.[\w_-]+)+))([\w.,@?^=%&:/~+#-]*[\w@?^=%&/~+#-]))

which includes the parenthesis - seems to find more (3,2006)
and href="http[s]?://.+?" finds 3,0033 In Text Crawler I did not try the \L\1 to convert to lower case since that is an option offered in the program, and running the above says it 3,0033 were changed, though it only change the case (I hope!).

I had also found HTML Tags Change To Uppercase or Lowercase Software that converts uppercase letters in links to lower case, though it is $20 if you want to convert more than one at a time, and is very slow or can locks up with large files. But it seemed to work well to convert upper case letters in links to lower case in files that I used it for.

I do not know regex (imagine a world in which this was the written language!) but was looking to convert all the upper case caps in links to lower case, and I searched a lot trying to find out how to do this.

1
  • Is this an answer or a new question?
    – joanis
    Commented Dec 8, 2021 at 22:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.