Hello group,
I am attempting to remove double quotes from the beginning and ending of a
string. Admittedly, I am not the best with regular expressions, but I do
have two that work with preg_replace(). Here they are:
$pattern = '[^"]'; <--- removes the beginning double quote
$pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to enclose
'.*' in parentheses and I get an unknown modifier '('.
This is getting beyond my regex knowledge, if anyone has any advice on this
it would be greatly appreciated.
Thanks in advance,
AJ Schroeder 6 5711
Schroeder, AJ wrote:
Hello group,
I am attempting to remove double quotes from the beginning and ending of a
string. Admittedly, I am not the best with regular expressions, but I do
have two that work with preg_replace(). Here they are:
$pattern = '[^"]'; <--- removes the beginning double quote
$pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to enclose
'.*' in parentheses and I get an unknown modifier '('.
This is getting beyond my regex knowledge, if anyone has any advice on this
it would be greatly appreciated.
Thanks in advance,
AJ Schroeder
when using preg_* you need escape chars for the expression....
your first patterns should look something like:
$pat = '`^"`'; // quote at beginning of string
$pat = '`"$`'; // quote at end of string
$pat = '`^"(.*)"$`'; // single-line string that starts and ends with a quote
--
Posted via a free Usenet account from http://www.teranews.com
Justin Koivisto wrote:
Schroeder, AJ wrote:
>Hello group,
I am attempting to remove double quotes from the beginning and ending of a string. Admittedly, I am not the best with regular expressions, but I do have two that work with preg_replace(). Here they are: $pattern = '[^"]'; <--- removes the beginning double quote $pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to enclose '.*' in parentheses and I get an unknown modifier '('.
This is getting beyond my regex knowledge, if anyone has any advice on this it would be greatly appreciated.
Thanks in advance,
AJ Schroeder
when using preg_* you need escape chars for the expression....
your first patterns should look something like:
$pat = '`^"`'; // quote at beginning of string
$pat = '`"$`'; // quote at end of string
$pat = '`^"(.*)"$`'; // single-line string that starts and ends with
a quote
Hmm, maybe I am that dense, but that last expression seemed to torch the
entire string and return nothing. The first two work no problem.
Still confused...
On Mon, 05 Nov 2007 20:11:49 +0100, Schroeder, AJ <aj*@qg.comwrote:
Hello group,
I am attempting to remove double quotes from the beginning and ending of
a
string. Admittedly, I am not the best with regular expressions, but I do
have two that work with preg_replace(). Here they are:
$pattern = '[^"]'; <--- removes the beginning double quote
$pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to
enclose
'.*' in parentheses and I get an unknown modifier '('.
Yes indeed.
The preg_* function expect a pattern like this:
(delimiter)(pattern)(delimiter)(modifiers)
You are free to choose your own delimiter ('/' is pretty standard), and a
second occurance of that character is assumed to end the pattern and start
the modifiers. (I'm actually quite ammazed it matches '[' to ']', a quite
rigid implementation would throw an error stating that " was an unknown
modifier).
$string = preg_replace('/(^"+|"+$)/','',$string);
--
Rik Wasmus
Schroeder, AJ wrote:
Justin Koivisto wrote:
>Schroeder, AJ wrote:
>>Hello group,
I am attempting to remove double quotes from the beginning and ending of a string. Admittedly, I am not the best with regular expressions, but I do have two that work with preg_replace(). Here they are: $pattern = '[^"]'; <--- removes the beginning double quote $pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to enclose '.*' in parentheses and I get an unknown modifier '('.
This is getting beyond my regex knowledge, if anyone has any advice on this it would be greatly appreciated.
Thanks in advance,
AJ Schroeder
when using preg_* you need escape chars for the expression....
your first patterns should look something like:
$pat = '`^"`'; // quote at beginning of string
$pat = '`"$`'; // quote at end of string
$pat = '`^"(.*)"$`'; // single-line string that starts and ends with a quote
Hmm, maybe I am that dense, but that last expression seemed to torch the
entire string and return nothing. The first two work no problem.
Still confused...
The last pattern assumes the string is a single line (no \r or \n in
it), and both begins and ends with "
This would match that pattern:
"The fox jumped over the lazy dog."
This would not:
The fox jumped over the "lazy" dog.
If you want to match as in the second string, try something more along
the lines of:
$pat = '`"([^"]*)"`';
When you are unsure how your patterns are matching, try something like
this to view it quickly:
if(preg_match_all($pat,$string,$m)){
echo '<pre>';
print_r($m);
echo '</pre>';
}
see the manual page for preg_match_all if you are not sure what the $m
array means.
--
Posted via a free Usenet account from http://www.teranews.com
Schroeder, AJ wrote:
Justin Koivisto wrote:
>Schroeder, AJ wrote:
>>Hello group,
I am attempting to remove double quotes from the beginning and ending of a string. Admittedly, I am not the best with regular expressions, but I do have two that work with preg_replace(). Here they are: $pattern = '[^"]'; <--- removes the beginning double quote $pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to enclose '.*' in parentheses and I get an unknown modifier '('.
This is getting beyond my regex knowledge, if anyone has any advice on this it would be greatly appreciated.
Thanks in advance,
AJ Schroeder
when using preg_* you need escape chars for the expression....
your first patterns should look something like:
$pat = '`^"`'; // quote at beginning of string
$pat = '`"$`'; // quote at end of string
$pat = '`^"(.*)"$`'; // single-line string that starts and ends with a quote
Hmm, maybe I am that dense, but that last expression seemed to torch the
entire string and return nothing. The first two work no problem.
Still confused...
The last pattern assumes the string is a single line (no \r or \n in
it), and both begins and ends with "
This would match that pattern:
"The fox jumped over the lazy dog."
This would not:
The fox jumped over the "lazy" dog.
If you want to match as in the second string, try something more along
the lines of:
$pat = '`"([^"]*)"`';
When you are unsure how your patterns are matching, try something like
this to view it quickly:
if(preg_match_all($pat,$string,$m)){
echo '<pre>';
print_r($m);
echo '</pre>';
}
see the manual page for preg_match_all if you are not sure what the $m
array means.
--
Posted via a free Usenet account from http://www.teranews.com
Rik Wasmus wrote:
On Mon, 05 Nov 2007 20:11:49 +0100, Schroeder, AJ <aj*@qg.comwrote:
>Hello group,
I am attempting to remove double quotes from the beginning and ending of a string. Admittedly, I am not the best with regular expressions, but I do have two that work with preg_replace(). Here they are:
$pattern = '[^"]'; <--- removes the beginning double quote $pattern = '["$]'; <--- removes the ending double quote
But when I try to make this all one statement with:
$pattern = '[^"].*["$]';
PHP throws a warning with an unknown modifier '.'. I then tried to enclose '.*' in parentheses and I get an unknown modifier '('.
Yes indeed.
The preg_* function expect a pattern like this:
(delimiter)(pattern)(delimiter)(modifiers)
You are free to choose your own delimiter ('/' is pretty standard),
and a second occurance of that character is assumed to end the
pattern and start the modifiers. (I'm actually quite ammazed it
matches '[' to ']', a quite rigid implementation would throw an error
stating that " was an unknown modifier).
$string = preg_replace('/(^"+|"+$)/','',$string);
Justin and Rik,
Thank you for the help! I am now able to strip off beginning and ending
quotes of strings. Although I am still messing around with different strings
to handle all the combination of strings I will have to process, I have a
great starting point.
Thank you again.
AJ Schroeder This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert Oschler |
last post by:
Can someone give me a regex expression that will split a sentence containing
words and double-quoted phrases, into an array? I don't want the words
between the double-quotes to be split using the...
|
by: Craig Kenisston |
last post by:
I have the sudden need to split a text that may have any of the
following tokens :
Words with quotes or double quotes.
Words with no quotes at all.
Numbers with and without decimal points, no...
|
by: William Stacey [MVP] |
last post by:
Would like help with a (I think) a common regex split example. Thanks for
your example in advance. Cheers!
Source Data Example:
one "two three" four
Optional, but would also like to...
|
by: JS |
last post by:
I am writing a C# app that needs to parse a sentence entered by the user
for a simple boolean search.
I need to capture all of the AND words that are not inside of double
quotes. However, I am...
|
by: Fuzzyman |
last post by:
Hello all,
I'm writing a module that takes user input as strings and (effectively)
translates them to function calls with arguments and keyword
arguments.to pass a list I use a sort of 'list...
|
by: jmchadha |
last post by:
I have got the following html:
"something in html ... etc.. city1... etc... <a class="font1"
href="city1.html" onclick="etc."click for <b>info</bon city1 </a>
... some html. city1.. can repeat...
|
by: Bragadiru |
last post by:
Hi,
I'm using the following Regex to parse for method parameters. It works if
there are no spaces between commas. How can I change the regex to support
method calls like : MyMethod('uno', ...
|
by: =?Utf-8?B?U2VyZ2V5IFBvYmVyZXpvdnNraXk=?= |
last post by:
Hi,
I need to replace double quotes inside the text from the database with " to
correctly display my text. I was trying to use Regex to perform such a task:
Regex.Replace(text, "", """)
to...
|
by: eBob.com |
last post by:
Is there a regex pattern which will match a VB.Net string? I.E. a regex
which matches ...
"this is a ""vb.net"" string"
(I don't want three matches in this case, I want one.) I've come up...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |