HardwareHeaven.com

HardwareHeaven.com

Looking for the skin chooser?
 
 
  • Home

  • Hardware reviews

  • Articles

  • News

  • Tools

  • Gaming at HardwareHeaven

  • Forums

 

Go Back   HardwareHeaven.com > Forums > Software / Tools > Programming, Coding, (Web)Design


Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people.

Reply
 
Thread Tools
Old Feb 13, 2003, 04:18 AM   #1
Yarr... I be blind!
 
Jeff's Avatar
 
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80
Jeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud of

Regular Expression...

Anybody have a regex code for quotes in a string, which can allow backslash escaped quotes in the string, example:

current:

<blah src="asdads" />

gets matched correctly, but if you need quotes:

<blah src="asda"asd" /> it would only count "asda", and ignore the rest, anybody know how I can make it work with:

<blah src="asda\"asd" />

???


(I'll figure it out eventually, but thought I'd ask too, can't hurt)
__________________
Jeff is offline   Reply With Quote


Old Feb 13, 2003, 04:46 AM   #2
Custom User Title
 
Join Date: May 2002
Location: Washington
Posts: 1,125
Rep Power: 0
Andrew275 will become famous soon enoughAndrew275 will become famous soon enough
System Specs

So you can't do:

/<blah src="(.*?)" \/>/

?
Andrew275 is offline   Reply With Quote
Old Feb 13, 2003, 05:11 AM Threadstarter Thread Starter   #3
Yarr... I be blind!
 
Jeff's Avatar
 
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80
Jeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud of

That's what I am currently using, but I want to be able to escape characters in between the quotes.
__________________
Jeff is offline   Reply With Quote
Old Feb 13, 2003, 05:12 AM Threadstarter Thread Starter   #4
Yarr... I be blind!
 
Jeff's Avatar
 
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80
Jeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud of

with that way, it counts this as the result: asda\ instead of asda"asd
__________________
Jeff is offline   Reply With Quote
Old Feb 18, 2003, 07:00 PM   #5
A Legend in Underwear
 
UberLord's Avatar
 
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 0
UberLord will become famous soon enough

Code:
<?php
$string = '<tag value="ahhh\"hehe" value2="dumb\"ass\"bunny" />';

$slen = strlen($string);
$lastChar = "";
$values = array();
$quoteStart = false;
for ($index = 0; $index < $slen; $index ++) {
	$char = $string[$index];
	if (($char == '"') && ($lastChar != "\\")) {
		if ($quoteStart) {
			$values[] = $thisValue;
		} else {
			$thisValue = "";
		}
		$quoteStart = ! $quoteStart;
	} else {
		if ($quoteStart) $thisValue .= $char;
	}
	$lastChar = $char;
}
print_r($values);
?>
Obviously you could get the tag names by testing for " " & "=" as well.
I'm sure it could be done using regex, but I do things the old fashioned way.

I know many varied ways of string handling after writing a full english text parser for a MUD with the following string commands available

STRING3 = STRING1 + STRING2
LEFT$(STRING, 10)
RIGHT$(STRING, 10)
MID$(STRING, 10, 5)
__________________
Gentoo Linux - Developer (baselayout)
Read my blog

"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours."
Stephen Roberts
UberLord is offline   Reply With Quote
Old Feb 18, 2003, 10:09 PM   #6
Custom User Title
 
Join Date: May 2002
Location: Washington
Posts: 1,125
Rep Power: 0
Andrew275 will become famous soon enoughAndrew275 will become famous soon enough
System Specs

Quote:
Originally posted by UberLord
[code]

<?php
STRING3 = STRING1 + STRING2
LEFT$(STRING, 10)
RIGHT$(STRING, 10)
MID$(STRING, 10, 5)
BASIC
Andrew275 is offline   Reply With Quote
Old Feb 18, 2003, 10:53 PM   #7
A Legend in Underwear
 
UberLord's Avatar
 
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 0
UberLord will become famous soon enough

Quote:
Originally posted by Andrew275
BASIC
It was either BASIC or 6502 assembly on the good old BBC Micro Model B
At age 5 I chose BASIC and happily wrote a text adventure game or 6 using full english parsers
At age 18 I was writing a "fake screen" program in 6502 that was sent back to the beeb in the system admins desk to hide what I was really doing
__________________
Gentoo Linux - Developer (baselayout)
Read my blog

"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours."
Stephen Roberts
UberLord is offline   Reply With Quote
Old Mar 25, 2003, 11:08 PM Threadstarter Thread Starter   #8
Yarr... I be blind!
 
Jeff's Avatar
 
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80
Jeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud ofJeff has much to be proud of

PHP Code:
preg_match_all('/("|\\')([^\1\\\]*?(?:\\\.[^\1\\\]*?)*)\1/s', $str, $result); 
__________________
Jeff is offline   Reply With Quote
Reply

Thread Tools