|
|||||||
| Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
Yarr... I be blind!
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
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)
__________________
|
|
|
|
|
|
#2 |
|
Custom User Title
|
So you can't do:
/<blah src="(.*?)" \/>/ ? |
|
|
|
|
|
|
|
Yarr... I be blind!
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
That's what I am currently using, but I want to be able to escape characters in between the quotes.
__________________
|
|
|
|
|
|
|
|
Yarr... I be blind!
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
with that way, it counts this as the result: asda\ instead of asda"asd
__________________
|
|
|
|
|
|
#5 |
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 0 ![]() |
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);
?>
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 |
|
|
|
|
|
#6 | |
|
Custom User Title
|
Quote:
|
|
|
|
|
|
|
#7 | |
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 0 ![]() |
Quote:
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 |
|
|
|
|
|
|
|
|
Yarr... I be blind!
Join Date: May 2002
Location: Calgary, Canada
Posts: 3,191
Rep Power: 80 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
PHP Code:
__________________
|
|
|
|
![]() |
| Thread Tools | |
|
|