Regex help, should be really simple

$newHTML = str_replace("<tr><td>1-30 of 699 results.1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>", "", $newHTML); $newHTML = str_replace("<tr><td>31-60 of 699 results.First &Acirc;&middot; Prev &Acirc;&middot; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>", "", $newHTML); $newHTML = str_replace("<tr><td>61-90 of 699 results.First &Acirc;&middot; Prev &Acirc;&middot; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>","",$newHTML); $newHTML = str_replace("<tr><td>91-120 of 699 results.First &Acirc;&middot; Prev &Acirc;&middot; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>","",$newHTML); $newHTML = str_replace("<tr><td>121-150 of 699 results.First &Acirc;&middot; Prev &Acirc;&middot; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>","",$newHTML);

The code above is me doing it without regex because I simply do not understand regex.

**<tr><td>**121-150 **of 699 results.First &Acirc;&middot; Prev &Acirc;&middot; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>**

Using above as an example, 121-150 are the only numbers that aren't constant in $newHTML. The rest of the string appears numerous times. How can I wildcard those spots? ie.

<tr><td>###-### of 699 results.First &Acirc;&middot; Prev &Acirc;&middot; 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>

Where the number signs are possible numbers that need to be removed.


It's pretty straightforward to convert your set of strings to a PHP regular expression. The considerations are:

\d+ stands for 1 or more digits, so you'll use that in place of each number.

\| stands for a vertical line, so you'll use that in place of each vertical line.

Consequently, a regular expression which will match the given set of strings is:

<tr><td>\d+-\d+ of \d+ results.First &Acirc;&middot; Prev &Acirc;&middot; 1 \| 2 \| 3 \| 4 \| 5 \| 6 \| 7 \| 8-15 &Acirc;&middot; Next &Acirc;&middot; Last</td></tr>

Category:php Time:2011-11-17 Views:1
Tags: php regex

Related post

  • Regex vs. string:find() for simple word boundary 2011-01-16

    Say I only need to find out whether a line read from a file contains a word from a finite set of words. One way of doing this is to use a regex like this: .*\y(good|better|best)\y.* Another way of accomplishing this is using a pseudo code like this:

  • Regex replace (in Python) - a simpler way? 2009-01-29

    Any time I want to replace a piece of text that is part of a larger piece of text, I always have to do something like: "(?P<start>some_pattern)(?P<replace>foo)(?P<end>end)" And then concatenate the start group with the new data for

  • When should I use a compiled Regex vs. interpreted? 2009-01-06

    After reading this article I understand the benefits of compiled regular expressions a little better, however in what personal scenarios would you consider mandates the use of a compiled Reg Ex? F

  • regex for email validation 2009-02-03

    I have written the regex below for a really simple email validation. I plan to send a confirmation link. /.*@[a-z0-9.-]*/i I would, however, like to enhance it from the current state because a string like this does not yield the desired result: test

  • How important is knowing Regexs? 2009-02-06

    My personal experience is that regexs solve problems that can't be efficiently solved any other way, and are so frequently required in a world where strings are as important as they are that not having a firm grasp of the subject would be sufficient

  • Regex - how to match everything except a particular pattern 2009-03-04

    How do I write a regex to match any string that doesn't meet a particular pattern? I'm faced with a situation where I have to match an (A and ~B) pattern. --------------Solutions------------- You could use a look-ahead assertion: (?!999)\d{3} This ex

  • What are alternatives to regexes for syntax highlighting? 2009-05-04

    While editing this and that in Vim, I often find that its syntax highlighting (for some filetypes) has some defects. I can't remember any examples at the moment, but someone surely will. Usually, it consists of strings badly highlighted in some cases

  • How do I use regex to replace non-word chars in a specific piece of string? 2009-05-05

    I have text file with a row like this: SendersTimeSeriesIdentification: COMPANY_A/COMPANY_B/REF_7/20090505 I'd like to replace all non-word chars in the value part with the character n, like this: SendersTimeSeriesIdentification: COMPANYnAnCOMPANYnBn

  • Best regex pattern for matching non SP1 IE6 in user agent string? 2009-05-09

    I needed some code to match all IE6 versions that are not SP1 (part of Windows XP SP2, confusing eh). This is to turn gzip off for versions of IE that do not handle it properly. The best I have come up with is: MSIE [1-6]\.(?!.*?SV1) Does anyone have

  • Regex to parse C# source code to find all strings 2009-06-08

    I asked this question a long time ago, I wish I had read the answers to When not to use Regex in C# (or Java, C++ etc) first! I wish to use Regex (regular expressions) to get a list of all strings in my C# source code, including strings that have dou

  • Regex to check fix length field with packed space 2009-08-11

    Say I have a text file to parse, which contains some fixed length content: 123jackysee 45678887 456charliewong 32145644 <3><------16------><--8---> # Not part of the data. The first three characters is ID, then 16 characters user na

  • Regex to validate at most 2 numbers and at most 4 alphabets in an string of length 6 2009-08-24

    Max Length of the String is 6. The string should contain at most 2 digits The string should contain at most 4 alphabets So the following examples should match abcd22 a1cd3d 11acde a1c 1ad --------------Solutions------------- What you want isn’t reall

  • Merge several regexes to a single one 2009-12-11

    I have several regexes (actually several thousands), and I must check if one string matches any of these regexes. It is not very efficient, so I would like to merge all these regexes as a single regex. For example, if a have these regexes: 'foo *bar'

  • Regex for getting content between $ chars from a text 2009-12-30

    The problem: I need to extract strings that are between $ characters from a block of text, but i'm a total n00b when it comes to regular expressions. For instance from this text: Li Europan lingues $es membres$ del sam familie. Lor $separat existenti

  • Parse numbers from string using regex in VB.NET 2010-02-16

    I am trying to parse the digits to store in a variable from a string in VB.NET (would like to also include the decimal point). Here is an example string: Refund issued for $27.74 --------------Solutions------------- As casperOne already pointed out,

  • Regex: Matching against groups in different order without repeating the group 2010-04-08

    Let's say I have two strings like this: XABY XBAY A simple regex that matches both would go like this: X(AB|BA)Y However, I have a case where A and B are complicated strings, and I'm looking for a way to avoid having to specify each of them twice (on

  • Help Me Writing a Simple Regular Expression 2010-06-05

    I have the following text: txtAddressSup.Text I want the Sup to be replaced by Cus while the whole text remains as is. I have many texts that are in this format: xxxxxxxSup.xxxxx --------------Solutions------------- It's not clear from your question

  • Does REGEX differ from PHP to Python 2010-06-18

    I found this post: but I actually did not get if Python's REGEX syntax matches PHP's REGEX syntax. I started to convert some of my old PHP code to python (due to g's appengine etc.),

  • PHP find words which are not in regex 2010-07-21

    I have written following regular expression /^[A-Za-z0-9-_\s]*$/ in PHP which allows numbers, letters, spaces, hyphen and underscore. I want to display those matches which are not valid against the regex i.e "My Name is Blahblah!!!" should give me "!

Copyright (C), All Rights Reserved.

processed in 0.610 (s). 13 q(s)