Search Results

Search found 9872 results on 395 pages for 'preg replace callback'.

Page 12/395 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • Use regular expressions to match an ? but not a \?

    - by J.Milly
    I have a PHP regular expression that has been functioning fairly well to parse some odd legacy client templates until recently when we found an escaped question mark (\?) included in a template expression. I'm not strong enough with my regular expression-fu to wrap my feeble noodle around a negative look ahead or some techno-mumbo-jumbo so, tips or points in the right direction would be greatly appreciated. My PHP: preg_match_all("/\{\{IF (.*)\?(.*):(.*)\}\}/U", $template, $m, PREG_SET_ORDER);

    Read the article

  • Regular Expression (preg_match_all)

    - by Helena
    This is my code: <?php $matchWith = "http://videosite.com/ID123"; preg_match_all('\S/videosite\.com\/(\w+)\S/i', $matchWith, $matches); foreach($matches[1] as $value) { print '<a href="http://videosite.com/'.$value.'"> Hyperlink </a>'; } ?> It's not working. I want to exclude every match that has a whitespace before or after the Link (with the ID). I used \S for this. For example if: $matchWith = " http://videosite.com/ID123 "; it should not display anything. Thank you.

    Read the article

  • php - preg_replace not working when string contains a hashtag

    - by Steven
    I found a function online for turning a url within a string into a clickable link. However, when the url contains a hashtag it doesn't work. eg. http://www.bbc.co.uk/radio1/photos/fearnecotton/5759/1#gallery5759 Here's the part of the function concerned: $ret = preg_replace( "#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t< ]*)#", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret ); $ret = preg_replace( "#(^|[\n ])((www|ftp)\.[^ \"\t\n\r< ]*)#", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret ); Any ideas? thanks

    Read the article

  • How to Ignore certain tags and replace texts in PHP

    - by Aakash Chakravarthy
    Hello, I have a variable like $content = "Lorem Ipsum is simply <b>dummy text of the printing</b> and typesetting industry. Lorem Ipsum has been the industry's <i>standard dummy text</i> ever since the 1500s <string>javascriptFunc();</script>" ; when i use str_replace('a', '', $content); all the 'a's get removed. But the 'a's within the <script> tag should not be removed. or is there any way to replace text other than this method Please help .

    Read the article

  • php replace regular expression

    - by Enkay
    I need to use php to add a space between a period and the next word/letter when there's none. For example, "This is a sentence.This is the next one." needs to become "This is a sentence. This is the next one." Notice the added space after the first period. My problem is that even if I'm able to make a regular expression that finds every dot followed by a letter, how do I then replace that dot with a "dot + space" and keep the letter? Also it needs to keep the case of the letter, lower or upper. Thanks for your input.

    Read the article

  • Java String Replace and null characters

    - by praspa
    Testing out someone elses code (of course it was ...) , I noticed a few JSP pages printing funky non-ascii characters. Taking a dip into the source I found this tidbit. // remove any periods from first name e.g. Mr. John --> Mr John firstName = firstName.trim().replace('.','\0'); Does replacing a character in a String with a null character even work in Java? I know that '\0' will terminate a c-string. Would this be the culprit to the funky characters? Thanks PR

    Read the article

  • Add links to specific words within span tag in PHP

    - by dazhall
    I have a list of words that I'd like to add a link to, I can do this fairly easily using preg_match_all and preg_replace: $str = "<span class=\"cz\">Dám si jedno pivo prosím.</span> = I'll have a beer please."; preg_match_all('/[a-ztúuýžácdéeínórš]+/i',$str,$matches); $matches = array_unique($matches[0]); foreach ($matches as $match) { if(!empty($words[$match])) { $str = preg_replace("/(^|[^\w]){1}(".preg_quote($match,"/").")($|[^\w]){1}/i", '\\1<a href="#">\\2</a>\\3', $str); } } echo $str; What I'd like to do is restrict the linking to only within the span tag. My brain is all regex-ed out, so any help would be appreciated! Thanks! Darren.

    Read the article

  • Remove newlines and spaces

    - by Cosmin
    How can I remove newline between <table> .... </table> and add \n after each ex: <table border="0" cellspacing="0" cellpadding="0" width="450" class="descriptiontable"><tr> <td width="50%" valign="top"> <span class="displayb">Model Procesor:</span> Intel Celeron<br><span class="displayb">Frecventa procesor (MHz):</span> 2660<br><span class="displayb">Placa Video:</span> Intel Extreme Graphics 2<br><span class="displayb">Retea integrata:</span> 10/100Mbps, RJ-45<br><span class="displayb">Chipset:</span> Intel 845G<br> </td> <td width="50%" valign="top"> <span class="displayb">Capacitate RAM (MB):</span> 512<br><span class="displayb">Tip RAM:</span> DDR<br> </td> </tr></table> and become : <table border="0" cellspacing="0" cellpadding="0" width="450" class="descriptiontable"><tr><td width="50%" valign="top"><span class="displayb">Model Procesor:</span> Intel Celeron<br><span class="displayb">Frecventa procesor (MHz):</span> 2660<br><span class="displayb">Placa Video:</span> Intel Extreme Graphics 2<br><span class="displayb">Retea integrata:</span> 10/100Mbps, RJ-45<br><span class="displayb">Chipset:</span> Intel 845G<br></td><td width="50%" valign="top"><span class="displayb">Capacitate RAM (MB):</span> 512<br><span class="displayb">Tip RAM:</span> DDR<br></td></tr></table>\n s.

    Read the article

  • regex preg_match|preg_match_all in php

    - by Josh
    I'm trying to come up with a regex that constructs an array that looks like the one below, from the following string $str = 'Hello world [something here]{optional}{optional}{optional}{n possibilities of this}'; So far I have /^(\*{0,3})(.+)\[(.*)\]((?:{[a-z ]+})?)$/ Array ( [0] => Array ( [0] => Hello world [something here]{optional}{optional}{optional}{n possibilities of this} [1] => [2] => Hello world [3] => something here [4] => {optional} [5] => {optional} [6] => {optional} [7] => ... [8] => ... [9] => {n of this} ) ) What would be a good approach for this? Thanks

    Read the article

  • Multiline Find & Replace in Visual Studio

    - by hawbsl
    Can it be done? We're using either VS2005 or VS2008. I don't mean regular expressions - which have their place - but plain old text find & replace. I know we can do it (at a pinch) with regular expressions using the \n tag but prefer not to get tangled up in regex escapes characters, plus there's a readability issue. If it can't be done what plain and simple (free) alternative are people using? That doesn't involve knocking up our own macro.

    Read the article

  • preg_match_all to parse an xml-like attribute string

    - by Rob
    I have a string like so: option_alpha="value" option_beta="some other value" option_gamma="X" ...etc. I'm using this to parse them into name & value pairs: preg_match_all("/([a-z0-9_]+)\s*=\s*[\"\'](.+?)[\"\']/is", $var_string, $matches) Which works fine, unless it encounters an empty attribute value: option_alpha="value" option_beta="" option_gamma="X" What have I done wrong in my regex?

    Read the article

  • preg_match find multiple partial appearances of a word in a string

    - by Rubytastic
    Any regex gurus around here? its driving me crazy. Say I have this string: "bookstore books Booking" I want to count the number "books" appears in this and return the number. Currently I have this which is not working: $string = "bookstore books Booking"; if (preg_match_all('/\b[A-Z]+books\b/', $string, $matches)) { echo count($matches[0]) . " matches found"; } else { echo "match NOT found"; } On top of this the "books" inside the preg_match_all should become a $var Anyone an idea how to count correctly?

    Read the article

  • sed: search and replace string with line number

    - by tigerstyle
    Hi volks, I have a XML file with a lot of empty tag attributes. For instance: <mytag id=""> <ontent>aaa</content> </mytag> <mytag id=""> <ontent>bbb</content> </mytag> <mytag id=""> <ontent>ccc</content> </mytag> Now I want to replace id="" with e.g. id="2443" (id="[linenumber]") I tried to do this with sed, but I did not get a successful result. I hope someone here can help me :-)

    Read the article

  • Complex pattern replacement using PHP preg_replace function ignoring quoted strings

    - by Saiful
    Consider the following string: this is a STRING WHERE some keywords ARE available. 'i need TO format the KEYWORDS from the STRING' In the above string keywords are STRING and WHERE Now i need to get an output as follows: this is a <b>STRING</b> <b>WHERE</b> some keywords ARE available. 'i need TO format the KEYWORDS from the STRING' So that the html output will be like: this is a STRING WHERE some keywords ARE available. 'i need TO format the KEYWORDS from the STRING' Note that the keywords within a quoted ('...') string will be ignored. in the above example i ignored the STRING keyword within the quoted string. Please give a modified version of the following PHP script so that I can have my desired result as above : $patterns = array('/STRING/','/WHERE/'); $replaces = array('<b>STRING</b>', '<b>WHERE</b>'); $string = "this is a STRING WHERE some keywords ARE available. 'i need TO format the KEYWORDS from the STRING'"; preg_replace($patterns, $replaces, $string);

    Read the article

  • mass add time in a file

    - by atinder
    i have a file in which time appears nearly hundred times like 00:01:32 00:01:33 00:01:36 ....................... how can i add 2 seconds or 2 minutes to all the times in the file so that i get 00:01:34 00:01:35 00:01:38 ..................

    Read the article

  • Replacing keywords in text with php & mysql

    - by intacto
    Hello, I have a news site containing an archive with more than 1 million news. I created a word definitions database with about 3000 entries, consisting of word-definition pairs. What I want to do is adding a definition next to every occurence of these words in the news. I cant make a static change as I can add a new keyword everyday, so i can make it realtime or cached. The question is, a str_replace or a preg_replace would be very slow for searching 3 thousand keywords in a text and replacing them. Are there any fast alternatives?

    Read the article

  • Python: replace urls with title names from a string

    - by Hellnar
    Hello I would like to remove urls from a string replace them with their titles of the original contents. For example: mystring = "Ah I like this site: http://www.stackoverflow.com. Also I must say I like http://www.digg.com" sanitize(mystring) # it becomes "Ah I like this site: Stack Overflow. Also I must say I like Digg - The Latest News Headlines, Videos and Images" For replacing url to the title, I have written this snipplet: #get_title: string -> string def get_title(url): """Returns the title of the input URL""" output = BeautifulSoup.BeautifulSoup(urllib.urlopen(url)) return output.title.string

    Read the article

  • Advanced replace in C#

    - by Andreas
    Hi, I like to replace some attributes inside a xml (string) with c#. Example xml: <items> <item x="15" y="25"> <item y="10" x="30"></item> </item> <item x="5" y="60"></item> <item y="100" x="10"></item> </items> In this case I like to change the x-attributes to the combined value of x and y. Result xml: <items> <item x="40" y="25"> <item y="10" x="40"></item> </item> <item x="65" y="60"></item> <item y="100" x="110"></item> </items>

    Read the article

  • Replace text in code with counting numbers

    - by Gpx
    Hi, due to testing and time measuring i have to write some kind of log into existing c# winforms code in Visual Studio 2010. I want to hold the changes and the work very small so my question is about replacing text in my call by counting numbers. Lets say i want to past a line like Log.WriteLine(position) many times in the code and then replace "position" with numbers starting from 1 to n in on turn. I cant use a counter in this case because of many loops i don´t get the right position. Thanks for any suggestions, Gpx

    Read the article

  • Javascript Regex Replace string, special character need help

    - by Mohummad Abdullah
    I am trying to replace string on page in runtime example: find string "(800).123.4567" to "<span>(800)123.4567</span>" means i want to add span tag before and after of string. here is i m doing this is my code: var avidno = '(800)123 1234'; function validate () { var regex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; if (regex.test(avidno)) { alert('bingo'); var altrstr = '<span>'+avidno+'</span>'; alert(altrstr); // Valid international phone number } else { alert('uupss'); // Invalid international phone number } } validate();

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >