Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I search for regular expressions like 'foo|bar' on webpages using Google Chrome or IE? I'm aware of the "Regular Expression Searcher" extension, but it does not work for me. (Nothing happens when I hit slash.) The reviews on the web store indicate that this is a common problem for many users.

share|improve this question
You don't use Firefox, but you might find one of its add-ons interesting: deeper web It doesn't do REs, but it does assist finer grained searching. If you're really desperate, you could always save the source of a web page and then search it with a utility or editor that does support REs, but that would be pretty ugly. – Joe Apr 30 '12 at 18:41
maybe use NotePad++ as external editor for web pages. There you can search for regexps. – alfred May 11 '12 at 14:53

Using Javascript to match regular expressions

Maybe you want try this at chrome's console:

var p=/.*(regu).+?\ /gi; console.log( document.body.innerText.match(p) );

Just open console, copy and paste above to console and hit enter. You can test it here at this page.
This can be improved if it fits in.

Here we print to console match indexes and matched text. Here we try to match text that contains regu, 20 chars before (or less if start of line) and 10 chars after (or less if eol).

var p=/.{0,20}regu[^ \n]+[^\n]{0,10}/gi;
while (m = p.exec(document.body.innerText)) { 
    console.log( 'Index: '+m.index+' Match: '+m ); }

Also try this, it will paint background of all matches on page red, rexexp is not perfect but at least it should not mess with HTML tags:

var p=/(\>{1}[^\n\<]*?)([^\n\<]{0,30}regu[^\n\<]{0,10})/gi,b=document.body;
b.innerHTML=b.innerHTML.replace(p,'$1<span style="background-color:red;">$2</span>');

Bookmarking this:

Another way to use this is through javascript: protocol (same code as just above):

javascript:(function(){var p=/(\>{1}[^\n\<]*?)([^\n\<]{0,30}regu[^\n\<]{0,10})/gi,b=document.body;b.innerHTML=b.innerHTML.replace(p,'$1<span style="background-color:red;">$2</span>');})();

For example, using javascript: protocol one can insert a little search box to any web page for searching regexp's.
I think that you already know that simple regexp can also used to remove red matches from page.
If I continue to develop this for few more hours we may have search plugin that fit in bookmark :)

share|improve this answer
Some previous versions of chrome do not support innerText. It is recommended to check if innerText is supported and default to textContent if innerText is not usable. – Spencer Doak Nov 25 '15 at 20:14

Regular Expression Search from Google Chrome.

A simple search utility that allows you to search a web page using regular expression.

Features under development

  • toggle through found results
  • improved UI
  • toggle between case sensitivity
  • create shortcut for toggling the extension
  • Allow pressing "Enter" key when searching (instead of clicking on search button)

Important Notes
This is a page action extension so it won't work right away on the page you have already opened. I recommend restart your browser before start using this extension. You can also try to refresh your opened page.

share|improve this answer
I don't have a better suggestion, but this extension doesn't work very well. While enabled, AdBlock doesn't block all ads. Also, after searching this page, for example, the add comment stops working. – Dennis Apr 29 '12 at 3:21

The other extensions that were mentioned didn't work for me, so I wrote my own open source chrome extension that you can try out here:

Source code is available on github:

share|improve this answer

not really a search, but I found this regexp highlighter (that I found somewhere) quite useful, and works for all browsers.

share|improve this answer
All the UUencoded chars makes it hard to read, I found what appears to be the multiline version at… – Alok May 2 '12 at 2:09
I use the regexp highlighter from this site and it works fairly well for me… – Error Mar 7 '13 at 14:00
I needed the normal (not bookmarklet) JS (for use in Chrome extension), and solution from @buffer link worked fine – Evgeniy Dolzhenko Jan 12 '14 at 22:30

In Chrome Developer Tools mode, type ctrl + shift + F (on Windows, not sure about other OS).

There's a reg-ex option for searching. This will search all files, so it will include JavaScript source. I'm not sure (how) you can limit it to only HTML.

share|improve this answer

Go to javascript:void((function(){b=document.body;b.innerHTML=b.innerHTML.replace(new RegExp("(>{1}[^\n\<]*?)([^\n\<]{0,30}"+prompt("Please enter the regular expression to search for.")+"[^\n\<]{0,10})", "g"),'$1'+prompt('Please enter the text to place before the occurrences.')+'$2'+prompt('Please enter the text to place after the occurrences.'))})())`.

share|improve this answer
This doesn't work when I put it in the URL bar. Would be cool though if it did. – Ahmed Jan 6 at 1:13
It also removes formatting :( – Solomon Ucko Mar 6 at 23:16
Also, the javascript: portion won't get pasted into the URL bar in Chrome. – Solomon Ucko Mar 6 at 23:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .