Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Browse by Tags

All Tags » preg_replace » php
  • How to match same pattern existing inside pattern?

    I have this kind of strings:  {test1|test2|test3} This is easy to match with something like:  ~{(.*?)}~  But I would like to be able to match strings like: {test1|test2|test3{subtest1|subtest2}} or {test1|test2|test3{subtest1|subtest2{subsubtest1|subsubtest2|subsubtest3}}} I can't figure out how I could match that in the ...
    Posted to Construction Advice (Forum) by www on February 13, 2011
  • Changing patterns depending on structure within substring

    Hi regex experts, I’m searching for a regular expression for PHP’s preg_replace() in order to adjust concatenated strings (no multi-line). These strings are fragments in German which form a sentence and therefore need to be (automatically) edited to adhere to grammar conventions. Roughly speaking, the regular expression should ...
    Posted to Construction Advice (Forum) by casualcoder on March 20, 2010
  • weird linebreak problem in php preg_replace

    what i'm trying to do is remove all line breaks in and around certain html (or xml if you will) elements (h[0-9], ul, li) from a string the following works fine for removing leading and trailing line breaks, but not the ones inside the element: $text = ...
    Posted to Construction Advice (Forum) by blarg on January 12, 2010
  • find if either stringa or stringb do not exist in a string

    I am working on making a bbcode system with php using preg_replace(), and I am making it so that other tags will not work inside of a code block. This is the code I am currently using, it almost works: /(?!\[code\])(.*)(\[b\])(.+)(\[\/b\])(.*)(?<!\[\/code\])/Usi  what I want it to do is if [*code] and [*/code] are around the text inside, ...
    Posted to Construction Advice (Forum) by sarathi on July 31, 2009
  • Replace matches in HTML

    I'm trying to find words in HTML that are between tags using PHP (v5.2.6) preg_replace. The following rules apply to the matches full word match only (can also be matched when adjacent to non-word characters such as commas, parenthesis, periods, question marks, exclamation marks, percentage, dollar signs) e.g. "test" would ...
    Posted to Construction Advice (Forum) by mrboskits on July 16, 2009
  • a challenging regex solution needed...

    I need the following string: [Link Name|Link Description] (this is standard mediawiki text for links) to become this: "Link Description"[Link Name] (this is a proprietary wiki format) Link Description and Link Name are arbitrary values...it will always be bracket, text, pipe, text, bracket I'm using php and I've attempted to ...
    Posted to Construction Advice (Forum) by slapshot on June 12, 2009
  • regular expression to replace the given instance of word in a text

    Hi, Anybody knows how to replace the second or third instance of word in a text using regular expression in php (preg_replace()) For example, I have an article about car and let's say the word car occurs 10 times. Now I want to replace the 3rd and 7th instance of car with some other word. How can I do this with php regular ...
    Posted to Discussion (Forum) by namus25 on November 5, 2008
  • BBCode conversion

    Hi, I asking for help in my PHP code optimization. I try to rewrite my old/slow BBCode conversion function to use regex. The allowed BBCodes are [ b]text[ /b] [ i]text[ /i] [ url]domain.com[ /url] or [ url]domain.com|domainname[ /url] [ img]filename.ext[ /img] or [ img]filename.ext|description[ /img] It is possible to construct ...
    Posted to Construction Advice (Forum) by pandor on August 23, 2008