Re: Find spaces with Regex

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



colinhumber@xxxxxxxxx wrote:

I need to find a regular expression that will pick up spaces that are
followed by either another space or an   expression.

I have been using the expression "(?<=) (?=[ &nbsp;])" which has been
working fine, except in the example "1 space", it is picking up the
space. I know it's because it's looking for a space, &, n, b, s, p, ;
character. How to I change the regular expression to look for a space
that is followed by a space or "&nbsp;"?

I've tried grouping the &nbsp; together using (?<=) (?=[ [&nbsp;]]) but
it isn't working.

This should work: " (?= |&nbsp;)"

The main problem with your expression are the brackets, which make no sense at all. Characters in brackets match alternately, so "[&nbsp;]*" would match "&nbsp;" but also "s&p;bn". The expression "[&nbsp;]" alone, without a quantifier like the * I added would only match a single one of the characters in the brackets.



               Oliver Sturm
--
omnibus ex nihilo ducendis sufficit unum
Spaces inserted to prevent google email destruction:
MSN oliver @ sturmnet.org Jabber sturm @ amessage.de
ICQ 27142619 http://www.sturmnet.org/blog
.



Relevant Pages

  • Re: Javascript Replace?
    ... Between the two forward slashes is the meat of the regular expression. ... is match any character that is not between the brackets ...
    (comp.lang.javascript)
  • Re: Find spaces with Regex
    ... > working fine, except in the example "1 space", it is picking up the ... > character. ... How to I change the regular expression to look for a space ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Extract domain names out of URLs
    ... Match the regular expression below and capture its match into backreference ... Between zero and one times, as many times as possible, giving back as needed ... A character in the range between ?A? ...
    (microsoft.public.excel)
  • Can anyone write this recursion for simple regexp more beautifully and clearly than the braggarts
    ... I know that lisp eval is written more clear than this recursion below ... The Practice of Programming ... The problem was that any existing regular expression package was far ... c Matches any literal character c. ...
    (comp.lang.c.moderated)
  • Re: RegEx: How to ignore the number of whitespaces?
    ... a "simpler" regular expression syntax is likely to bite you eventually, ... but that some of these character sequences may be "marked" as ... This is a regular expression "if" conditional statement, ... do not understand why the pattern "personal computer" will only match ...
    (microsoft.public.dotnet.framework)