Hi, I am trying to write a regexp that removes file paths from links and images.
href="path/path/file" to href="file"
href="/file" to href="file"
src="/path/file" to src="file"
and so on...
I thought that I had it working, but it messes up if there are two paths in the string it is working on. I think my expression is too greedy. It finds the very last file in the entire string.
This is my code that shows the expression messing up on the test input:
<script type="text/javascript" src="/javascripts/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var s = '<a href="one/keepthis"><img src="/one/two/keep.this"></a>';
var t = s.replace(/(src|href)=("|').*\/(.*)\2/gi,"$1=$2$3$2");
alert(t);
});
</script>
It gives the output:
<a href="keep.this"></a>
The correct output should be:
<a href="keepthis"><img src="keep.this"></a>
Thanks for any tips!
I'm building a MySQL query but I can't seem to get it right.
I have four tables:
- customers
- orders
- sales_rates
- purchase_rates
There is a 1:n relation 'customernr' between customers and orders.
There is a 1:n relation 'ordernr' between orders and sales_rates.
There is a 1:n relation 'ordernr' between orders and purchase_rates.
What I would like to do is produce an output of all customers with their total purchase and sales amounts.
So far I have the following query.
SELECT c.customernr, c.customer_name, SUM(sr.sales_price) AS sales_price, SUM(pr.purchase_price) AS purchase_price
FROM orders o, customers c, sales_rates sr, purchase_rates pr
WHERE o.customernr = c.customernr
AND o.ordernr = sr.ordernr
AND o.ordernr = pr.ordernr
GROUP BY k.bedrijfsnaam
The result of the sales_price and purchase_price is far too high. I seem to be getting double counts. What am I doing wrong? Is it possible to perform this in a single query?
Thank for your response!
I'm trying to extract the # of minutes from a text field using Oracle's REGEXP_SUBSTR() function.
Data:
Treatment of PC7, PT1 on left. 15 min.
15 minutes.
15 minutes
15 mins.
15 mins
15 min.
15 min
15min
15
In each case, I'm hoping to extract the '15' part of the string.
Attempts:
\d+ gets all of the numeric values, including the '7' and '1', which is undesirable.
(\d)+(?=\ ?min) get the '15' from all rows except the last.
(?((\d)+(?=\ ?min))((\d)+(?=\ ?min))|\d+), an if-else statement, doesnt' match anything.
What is wrong with my if-else statement?
Hello,
Let's suppose that we have such HTML code. We need to get all <a href=""></a> tags which DO NOT contain img tag inside it.
<a href="http://domain1.com"><span>Here is link</span></a>
<a href="http://domain2.com" title="">Hello</a>
<a href="http://domain3.com" title=""><img src="" /></a>
<a href="http://domain4" title=""> I'm the image <img src="" /> yeah</a>
I'm using this regular expression to find out all links
preg_match_all("!<a[^>]+href=\"?'?([^ \"'>]+)\"?'?[^>]*>(.*?)</a>!is", $content, $out);
I can modify it
preg_match_all("!<a[^>]+href=\"?'?([^ \"'>]+)\"?'?[^>]*>([^<>]+?)</a>!is", $content, $out);
But how can I tell to exclude results containing <img substring inside of <a href=""></a>?
Thank you
I'm trying to extract some results from a download manager, the format is:
[#8760e4 4.3MiB/40MiB(10%) CN:2 DL:4.9MiB ETA:7s]
what I'd like to extract from the above example, would be an array that looks like this:
['4.3','MiB','40','MiB','10%','4.9','MiB','7','s']
I've tried to split this in various combinations, but nothing seems to be right. Would anyone happen to know how to do this or be able to offer suggestions?
Thank you!
i have this code for get data from textfield:
<script type="text/javascript">
var mod=document.getElementById("mod").value;
ajax(mod);
function callback() {
if(ajaxObj(mod) {
document.getElementById("divResult").innerHTML=ajaxObj.responseText;
});
};
</script>
and this one for search character:
<script>
var str="KD-R435MUN2D";
var matches=str.match(/([EJU]).*(D)/i);
if (matches) {
var firstletter = matches [1];
var secondletter = matches [2];
var thirdletter = matches [3];
alert(firstletter + secondletter + thirdletter);
}else{
alert (":(");
}
</script>
how to combine both?please help...
How can convert the below youtube urls
$url1 = http://www.youtube.com/watch?v=136pEZcb1Y0&feature=fvhl
$url2 = http://www.youtube.com/watch?feature=fvhl&v=136pEZcb1Y0
into
$url_embedded = http://www.youtube.com/watch/v=136pEZcb1Y0
using Regular Expressions?
I need to get all characters between '(' and ')' chars.
var str = "dfgdgdfg (aaa.bbb) sfd (c) fdsdfg ( ,ddd (eee) )";
In this example, I need to get 3 strings:
(aaa.bbb)
(c)
( ,ddd (eee) )
What pattern I have to write? Please, help.
I need a regular expression with the following needs:
the string is alphanumeric and have exactly 6 characters in the first half followed by hyphen(optional) followed by optional 4 characters:(cannot have more than 4 characters in the second half)
so any of the following is valid
11111A
111111-1
111111-yy
yyyyy-989
yyyyyy-9090
i thought this expression /[a-zA-Z0-9]([-])?[a-zA-Z0-9]{5,10}$/; should work but i m unable to get it working correctly.
Any help will be appreciated,
This my simple data : <table></table><table></table><table>aaa</table>
how to match <table></table><table></table>***<table>aaa</table>***
it should be return <table></table><table></table>
Hi,
I'm trying to preg_replace charset=blablabla; and charset=blablabla" with charset=utf-8; and charset=utf-8". Please see ; = and " characters, and of course searched string can be lower/uppercase.
Can you help me?
Hi,
I would like to remove tag like the following one with its attributes using C# .Net
how can i do it?
<aaa type="1" class="2" />
other tags like <bbb type="5" class="4" /> i would like to keep.
Best Regards,
Hi,
I've a free text field on my form where the users can type in anything. Some users are pasting text into this field from Word documents with some weird characters that I don't want to go in my DB. (e.g. webding font characters) I'm trying to get a regular expression that would give me only the alphanum and the punctuation characters.
But when I try the following, the output is still all the characters. How can I leave them out?
<html><body><script type="text/javascript">var str="???????";document.write(str.replace(/[^a-zA-Z 0-9 [:punct]]+/g, " "));</script></body></html>
Hello,
I've been trying to find a string in PHP that matches something like this:
Currently I've tried something like this;
<()\?php eval(^
but it dosen't seem to get the string correctly.
After seeing several threads rubbishing the regexp method of finding a term to match within an HTML document, I've used the Simple HTML DOM PHP parser (http://simplehtmldom.sourceforge.net/) to get the bits of text I'm after, but I want to know if my code is optimal. It feels like I'm looping too many times. Is there a way to optimise the following loop?
//Get the HTML and look at the text nodes
$html = str_get_html($buffer);
//First we match the <body> tag as we don't want to change the <head> items
foreach($html->find('body') as $body) {
//Then we get the text nodes, rather than any HTML
foreach($body->find('text') as $text) {
//Then we match each term
foreach ($terms as $term) {
//Match to the terms within the text nodes
$text->outertext = str_replace($term, '<span class="highlight">'.$term.'</span>', $text->outertext);
}
}
}
For example, would it make a difference to determine check if I have any matches before I start the loop maybe?
How can I match the following pattern?
"anything123.anythingelse"
Alphanum of any length, with exactly 1 "." in the middle, and then alphanum of any length?
Thanks.
I need to get all characters between '(' and ')' chars.
var str = "dfgdgdfg (aaa.bbb) sfd (c) fdsdfg ( ,ddd (eee) )";
In this example, I need to get 3 strings:
(aaa.bbb)
(c)
( ,ddd (eee) )
What pattern I have to write? Please, help.
In this text:
warning here
there are several types of warnings
in this string warning.gif
at the end warning
end of line warning
I want to match every warning except warning.gif.
I cannot seem to get it to include the last one that has no character (control or otherwise) after it.
using warnings?[^\.] gets what I want except for the last warning (on the last line). I think because there is no character at all after. How can I get it to include that one?
Hello
I want a regular expression which will ignore the sentence containing "XYZ" character.
I am using this but this is not working
"(.+[^XYZ])"
Thanks in advance
Hi,
How can I take a line like this:
Digital Presentation (10:45), (11:30), 12:00, 12:40, 13:20, 14:00, 14:40, 15:20, 16:00, 16:40, 17:20, 18:00, 18:40, 19:20, 20:00, 20:40, 21:20, 22:00, 22:40, 23:10, 23:40.
And match all the 24 hour times so I can convert to a more human readable format using date()?
Also I want to match times in the 24:00-24:59 range too
Thanks!