My pattern looks something like
<xxxx location="file path/level1/level2" xxxx some="xxx">
I am only interested in the part in quotes assigned to location. Shouldn't it be as easy as below without the greedy switch? Does not seem to work :(
/.*location="(.*)".*/
Recently I came across a character range that was the following:
[/-+]
My very simple question is, is this even a valid charectar range? If so, what range of charectars would it match?
Got this function for ammending the query string and was wondering what the replacement part of the pre_replace meant (ie- $1$2$4).
function add_querystring_var($url, $key, $value) {
$url = preg_replace('/(.*)(\?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
if (strpos($url, '?') === false) {
return ($url . '?' . $key . '=' . $value);
} else {
return ($url . '&' . $key . '=' . $value);
}
}
Not too familiar with regular expression stuff. I get the various parts to preg_replace but not 100% about the use of '$1$2$4' in the replacement part.
In php how would I grab all javascript from a page given it's url? Is there a good regular expression to get the src of all javascript script tags or the script inside of them?
For example, scanning the contents of an HTML page with a Perl regular expression, I want to match all file extensions but not TLD's in domain names. To do this I am making the assumption that all file extensions must be within double quotes.
I came up with the following, and it is working, however, I am failing to figure out a way to exclude the TLDs in the domains. This will return "com", "net", etc.
m/"[^<>]+\.([0-9A-Za-z]*)"/g
Is it possible to negate the match if there is more than one period between the quotes that are separated by text? (ie: match foo.bar.com but not ./ or ../)
Edit I am using $1 to return the value within parentheses.
I need to do a find and replace in Notepad of
Err.Number, canBeAnything, canBeAnything, Err.Description
(where canBeAnything is just what it says)
with
Err.Number, "canBeAnything", "canBeAnything", Err.Description
(basically, put quotes around canBeAnything)
I got as far as the find
Err.Number, .+, .+, Err.Description
But I'm stuck on the replace. Any suggestions?
Let's say I have a string like so:
$file = 'widget-widget-newsletter.php';
I want to use preg_replace() to remove the prefix widget- and to remove the suffix .php . Is it possible to use one regular expression to achieve all this?
The resulting string should be widget-newsletter.
Is there any way to tell sed to output only captured groups? for example given by input:
This is a sample 123 text and some 987 numbers
and pattern
/([\d]+)/
I could get only 123 and 987 output in the way formatted by back references perhaps?
Recently I came across a character range that was the following:
[/-+]
My very simple question is, is this even a valid character range? If so, what range of characters would it match?
With a cURL request I load a complete website into a variable: $buffer.
In the source of the site there are two labels in between which my relevant content is placed.
****** bunch of code *******
<!-- InstanceBeginEditable name="Kopij" -->
this part I want to store in a match
<!-- InstanceEndEditable -->
****** bunch of code *******
I've been messing around with preg_match and its regexp. Can someone try to help me?
Thanx in advance.
I know i can do something like ab[^c]+def which should match ab_blah_hi_blah_def but is there a way to do something like
ab(^hi)+def
which will exclude the word hi causeing ab_blah_hi_blah_def to fail? but not ab_blah_h_i_blah_def
My web page content is populated by a plain text that is retrieved from a CDATA format - plain text data.
This is the site http://checksite.apsx to get information.
For more information, visit http://moresites.com/FAQ/index.html or search the site.
Now, my goal is to convert this plain text to a valid hyperlinks.
I've used a javascript code that does the conversion - /((http|https|ftp):\/\/[^ ]+)/g;
, but sometimes if there are multiple words, it captures an invalid URL.
My question: Is there a way to strictly capture any string that starts with "http" AND ends with ".html" or "aspx" will be converted into a valid hyperlink?
it should look like this -
This is the site http://checksite.apsx to get information.
For more information, visit http://moresites.com/FAQ/index.html or search the site.
I have the following text:
txtAddressSup.Text
I want the Sup to be replaced by Cus while the whole text remains as is. I have many texts that are in this format:
xxxxxxxSup.xxxxx
while($row = mysql_fetch_row($result)){
preg_match('#<span id="lblNumerZgloszenia" style="font-weight:bold;font-style:italic;">([^<]*)<\/span>#',$row[1],$matches);
$query2 = 'UPDATE content_pl SET kategoria_data='.$matches[1].' WHERE id='.$row[0].';';
mysql_query($query2);
}
I'm doing this preg_match to get the span contents into $matches array.
When I do a print_r($matches), it shows the right results but when I use $matches[1], it browser tells me that there is no such index.
Hello
var myarr= Array('test1','test2','test3');
var searchTerm = "test";
var rSearchTerm = new RegExp( searchTerm,'i');
$.each(myarr, function(i) {
if (myarr[i].match(rSearchTerm)) {
//item found
}
});?
guys is there any way to make my search algorithm better ? "myarr" will be a big array so i want to make sure that i'm using the best way to search in it
thanks alot
Suppose I have 500 rows of data, each with a paragraph of text (like this paragraph). That's it.I want to do a search that is not only based on words. (%LIKE%, not FULL_TEXT)
What would be faster?
SELECT * FROM ...WHERE LIKE "%query%"; This would put load on the database server.
Select all. Then, go through each one and do .find = 0 This would put load on the web server.
This is a website, and people will be searching frequently.
Sorry for these silly Question but i couldn't find a clue on my own
I am a beginner at regexp language and I want someone help to find and replace the following value in content-range Http=Header
Content-Range: bytes x-xxxxx/xxxx
i want to find the xxxx value and replace it with yyyyy so the value will be
x-xxxxxx/yyyy
for example
0-423423/7777777 to be 0-423423/9999999
Can anyone help me in it
thanks in advance
Hi All,
I want word '90%' to be matched with my String "I have 90% shares of this company".
how can I write regular expression for same?
I tried something like this:
Pattern p = Pattern.compile("\\b90\\%\\b", Pattern.CASE_INSENSITIVE
| Pattern.MULTILINE);
Matcher m = p.matcher("I have 90% shares of this company");
while (m.find()){
System.out.println(m.group());
}
but no luck.
Can any one thow some lights on this?
Many thanks,
Archi
Hi,
How to replace symbol "%" with a word "Percent".
My original string is "Internal (%) External (%)".
The string should be "Internal (Percent) External (Percent)"
Using regular expression, how I can replace this symbol?
Thanks in advance.
Atul
if I want to validate the input of a <textarea>, and want it to contain, for example, only numerical values, but even want to give users the possibility to insert new lines, I can selected wanted characters with a javascript regex that includes even the whitespace characters.
/[0-9\s]/
The question is: do a whitecharacter can be used to perform injections, XSS,even if I think this last option is impossible, or any other type of attack ?
thanks