SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    please explain regular expression

    /\b\W(damn|sloop|noway|nowhere)\W\b/i

    what all possible values it will match and if some can explain me what it does will be great help.

    What i understand if your string match any of the word given in list it should match.

    b\b is for word boundary but enthu to know why \W is added ?

  2. #2
    SitePoint Addict wibble wobble's Avatar
    Join Date
    Dec 2008
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We cant tell "why \W is added" -- it could be there for any reason depending on what its meant to do.

    \W is any "non-word" character, as the manual says:
    http://uk2.php.net/manual/en/referen...ern.syntax.php
    http://www.regular-expressions.info/php.html
    Find freelance jobs from all the major sites in one place:
    on twitter / on the web / twitter rss feed

  3. #3
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    \W is a non-word character and is redundant here (if the regex is supposed to match what I think it's supposed to match).

    \b doesn't match any character. It matches between word character and non-word character.

  4. #4
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi agree with you decowski i think if i re-write this expression simply /\b(damn|sloop|noway|nowhere)\b/i

    it will match

    sbc damn
    sloop away
    out to noway

    right??

  5. #5
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's correct. If you leave the \W in then it will match the spaces surrouning the words as well.

  6. #6
    SitePoint Evangelist priti's Avatar
    Join Date
    Aug 2006
    Location
    India
    Posts
    488
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $pattern = '/<Insurers>(.*)<\/Insurers\>/';
    preg_match_all($pattern, $xml, $matches);

    print_r($matches);

    i have a xml string from which i want to extract all <insurer> in different part of string..
    .
    .
    .
    <xs:schema id="Insurers" xmlns="" xmlnss="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-comml-msdata">
    </xs:schema>
    - <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-comml-msdata" xmlns:diffgr="urn:schemas-microsoft-comml-diffgram-v1">
    <Insurers>
    <Insurer diffgr:id="Insurer10" msdata:rowOrder="0">
    <insurer>AdfgfA</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer20" msdata:rowOrder="1">
    <insurer>AEdfgg</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer30" msdata:rowOrder="2">
    <insurer>345345</insurer>
    </Insurer>
    </Insurers>
    .
    .


    i want only

    <Insurers>
    <Insurer diffgr:id="Insurer10" msdata:rowOrder="0">
    <insurer>AdfgfA</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer20" msdata:rowOrder="1">
    <insurer>AEdfgg</insurer>
    </Insurer>
    <Insurer diffgr:id="Insurer30" msdata:rowOrder="2">
    <insurer>345345</insurer>
    </Insurer>
    </Insurers>

    how can i do this??


    .

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    That's a totally different question. Why didn't you start your own thread, it has nothing to do with the question in this one.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •