Search Results

Search found 7634 results on 306 pages for 'preg replace'.

Page 8/306 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • 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

  • Regex preg_match issue with commas

    - by Serge Sf
    This is my code to pre_match when an amount looks like this: $ 99.00 and it works if (preg_match_all('/[$]\s\d+(\.\d+)?/', $tout, $matches)) { $tot2 = $matches[0]; $tot2 = preg_replace("/\\\$/", '', $tot2);} I need to do the same thing for a amount that looks like this (with a comma): $ 99,00 Thank you for your help (changing dot for comma do not help, there is an "escape" thing I do not understand... Idealy I need to preg_match any number that looks like an amount with dot or commas and with or without dollar sign before or after (I know, it's a lot to ask :) since on the result form I want to scan there are phone and street numbers... UPDATE (For some reason I cannot comment on replies) : To test properly, I need to preg_replace the comma by a dot (since we are dealings with sums, I don't think calculations can be done on numbers with commas in it). So to clarify my question, I should say : I need to transform, let's say "$ 200,24" to "200.24". (could be amounts bettween 0.10 to 1000.99) : $tot2 = preg_replace("/\\\$/", '', $tot2);} (this code just deals with the $ (it works), I need adaptation to deal also with the change of (,) for (.))

    Read the article

  • How does MatchEvaluator works? ( C# regex replace)

    - by Marin Doric
    This is the input string 23x * y34x2. I want to insert " * " (star surrounded by whitespaces) after every number followed by letter, and after every letter followed by number. So my input string would look like this: 23 * x * y * 34 * x * 2. This is the regex that does the job: @"\d(?=[a-z])|a-z". This is the function that I wrote that inserts the " * ". Regex reg = new Regex(@"\d(?=[a-z])|[a-z](?=\d)"); MatchCollection matchC; matchC = reg.Matches(input); int ii = 1; foreach (Match element in matchC)//foreach match I will find the index of that match { input = input.Insert(element.Index + ii, " * ");//since I' am inserting " * " ( 3 characters ) ii += 3; //I must increment index by 3 } return input; //return modified input My question how to do same job using .net MatchEvaluator? I'am new to regex and don't understand good replacing with MatchEvaluator. This is the code that I tried to wrote: Regex reg = new Regex(@"\d(?=[a-z])|[a-z](?=\d)"); MatchEvaluator matchEval = new MatchEvaluator(ReplaceStar); input = reg.Replace(input, matchEval); return input; } public string ReplaceStar( Match match ) { //return What?? }

    Read the article

  • How to temporarily replace one primitive type with another when compiling to different targets in c#

    - by Keith
    How to easily/quickly replace float's for doubles (for example) for compiling to two different targets using these two particular choices of primitive types? Discussion: I have a large amount of c# code under development that I need to compile to alternatively use float, double or decimals depending on the use case of the target assembly. Using something like “class MYNumber : Double” so that it is only necessary to change one line of code does not work as Double is sealed, and obviously there is no #define in C#. Peppering the code with #if #else statements is also not an option, there is just too much supporting Math operators/related code using these particular primitive types. I am at a loss on how to do this apparently simple task, thanks! Edit: Just a quick comment in relation to boxing mentioned in Kyles reply: Unfortunately I need to avoid boxing, mainly since float's are being chosen when maximum speed is required, and decimals when maximum accuracy is the priority (and taking the 20x+ performance hit is acceptable). Boxing would probably rules out decimals as a valid choice and defeat the purpose somewhat. Edit2: For reference, those suggesting generics as a possible answer to this question note that there are many issues which count generics out (at least for our needs). For an overview and further references see Using generics for calculations

    Read the article

  • jQuery find value then replace SRC

    - by Charles Web Dev
    Hello all, Can anyone see anything that is wrong with this code it just isn't working... I am tring to: get the value of #product-variants-option-0 search #preload for the relevant image and then change div.image img src to that image jQuery(document).ready(function($) { $('#product-variants-option-0').change(function() { // What is the sku of the current variant selection. var select_value = $(this).find(':selected').val(); if (select_value == "Kelly Green") { var keyword = "kly"; }; var new_src = $('#preload img[src*=keyword]'); $('div.image img').attr('src', new_src); }); }); The selection: <select class="single-option-selector-0" id="product-variants-option-0"> <option value="Kelly Green">Kelly Green</option> <option value="Navy">Navy</option> <option value="Olive">Olive</option> <option value="Cocoa">Cocoa</option> </select> I'm trying to search an unordered list: <ul id="preload" style="display:none;"> <li><img src="0z-kelly-green-medium.jpg"/></li> <li><img src="0z-olive-medium.jpg"/></li> </ul> The image I'm trying to replace is this:

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >