regular expression and forward slash
i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" .
Even using preg_quote($find,'/')
, which escapes it, i still get the message:
Unknown modifier 't' in /frontend.functions.php on line 71
If i print the find pattern, it shows /time\/emit/
. Without preg_quote, it shows /time/emit/
and both return the same error message.
Any bit of knowledge would be useful.
php regex preg-replace
add a comment |
i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" .
Even using preg_quote($find,'/')
, which escapes it, i still get the message:
Unknown modifier 't' in /frontend.functions.php on line 71
If i print the find pattern, it shows /time\/emit/
. Without preg_quote, it shows /time/emit/
and both return the same error message.
Any bit of knowledge would be useful.
php regex preg-replace
add a comment |
i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" .
Even using preg_quote($find,'/')
, which escapes it, i still get the message:
Unknown modifier 't' in /frontend.functions.php on line 71
If i print the find pattern, it shows /time\/emit/
. Without preg_quote, it shows /time/emit/
and both return the same error message.
Any bit of knowledge would be useful.
php regex preg-replace
i'm searching for keywords in a string via a regular expression. It works fine for all keywords, exept one which contains a forward slash in it: "time/emit" .
Even using preg_quote($find,'/')
, which escapes it, i still get the message:
Unknown modifier 't' in /frontend.functions.php on line 71
If i print the find pattern, it shows /time\/emit/
. Without preg_quote, it shows /time/emit/
and both return the same error message.
Any bit of knowledge would be useful.
php regex preg-replace
php regex preg-replace
asked Jun 29 '10 at 22:32
pixeline
15.2k87295
15.2k87295
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
Try to begin and end your regular expression with different sign than /
I personally use `
I've seen people using #
I think most chars are good. You can read more about it here: http://pl.php.net/manual/en/regexp.reference.delimiters.php
Like this:
preg_match('#time/emit#', $subject); // instead of /time/emit/
To put it another way: Your $find
variable should contain rather #time/emit# than /time/emit/
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
add a comment |
looks like you have something already escaping it..
preg_quote('time/emit') // returns time/emit
preg_quote('time/emit') // returns time\/emit
as a hack you could simply do:
preg_quote(stripslashes($find)) // will return time/emit
add a comment |
bit of code?
the the 'regex' for that particular term should look something like '/time/emit/'. With a set of keywords there may be a more efficient method so seeing what you are doing would be good.
add a comment |
this should work:
$a="Hello////////";
$b=str_replace($a,"//","/");
echo $b;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3145264%2fregular-expression-and-forward-slash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try to begin and end your regular expression with different sign than /
I personally use `
I've seen people using #
I think most chars are good. You can read more about it here: http://pl.php.net/manual/en/regexp.reference.delimiters.php
Like this:
preg_match('#time/emit#', $subject); // instead of /time/emit/
To put it another way: Your $find
variable should contain rather #time/emit# than /time/emit/
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
add a comment |
Try to begin and end your regular expression with different sign than /
I personally use `
I've seen people using #
I think most chars are good. You can read more about it here: http://pl.php.net/manual/en/regexp.reference.delimiters.php
Like this:
preg_match('#time/emit#', $subject); // instead of /time/emit/
To put it another way: Your $find
variable should contain rather #time/emit# than /time/emit/
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
add a comment |
Try to begin and end your regular expression with different sign than /
I personally use `
I've seen people using #
I think most chars are good. You can read more about it here: http://pl.php.net/manual/en/regexp.reference.delimiters.php
Like this:
preg_match('#time/emit#', $subject); // instead of /time/emit/
To put it another way: Your $find
variable should contain rather #time/emit# than /time/emit/
Try to begin and end your regular expression with different sign than /
I personally use `
I've seen people using #
I think most chars are good. You can read more about it here: http://pl.php.net/manual/en/regexp.reference.delimiters.php
Like this:
preg_match('#time/emit#', $subject); // instead of /time/emit/
To put it another way: Your $find
variable should contain rather #time/emit# than /time/emit/
edited Jun 29 '10 at 22:47
answered Jun 29 '10 at 22:39
Kamil Szot
11.2k64657
11.2k64657
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
add a comment |
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
the back tick did the trick !
– pixeline
Jun 29 '10 at 23:35
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
Elegant solution that solved all of my headaches with the slash character.
– Seth
Sep 25 '12 at 23:59
add a comment |
looks like you have something already escaping it..
preg_quote('time/emit') // returns time/emit
preg_quote('time/emit') // returns time\/emit
as a hack you could simply do:
preg_quote(stripslashes($find)) // will return time/emit
add a comment |
looks like you have something already escaping it..
preg_quote('time/emit') // returns time/emit
preg_quote('time/emit') // returns time\/emit
as a hack you could simply do:
preg_quote(stripslashes($find)) // will return time/emit
add a comment |
looks like you have something already escaping it..
preg_quote('time/emit') // returns time/emit
preg_quote('time/emit') // returns time\/emit
as a hack you could simply do:
preg_quote(stripslashes($find)) // will return time/emit
looks like you have something already escaping it..
preg_quote('time/emit') // returns time/emit
preg_quote('time/emit') // returns time\/emit
as a hack you could simply do:
preg_quote(stripslashes($find)) // will return time/emit
answered Jun 29 '10 at 22:41
nathan
4,52611618
4,52611618
add a comment |
add a comment |
bit of code?
the the 'regex' for that particular term should look something like '/time/emit/'. With a set of keywords there may be a more efficient method so seeing what you are doing would be good.
add a comment |
bit of code?
the the 'regex' for that particular term should look something like '/time/emit/'. With a set of keywords there may be a more efficient method so seeing what you are doing would be good.
add a comment |
bit of code?
the the 'regex' for that particular term should look something like '/time/emit/'. With a set of keywords there may be a more efficient method so seeing what you are doing would be good.
bit of code?
the the 'regex' for that particular term should look something like '/time/emit/'. With a set of keywords there may be a more efficient method so seeing what you are doing would be good.
answered Jun 29 '10 at 22:39
Ian Wood
5,25352767
5,25352767
add a comment |
add a comment |
this should work:
$a="Hello////////";
$b=str_replace($a,"//","/");
echo $b;
add a comment |
this should work:
$a="Hello////////";
$b=str_replace($a,"//","/");
echo $b;
add a comment |
this should work:
$a="Hello////////";
$b=str_replace($a,"//","/");
echo $b;
this should work:
$a="Hello////////";
$b=str_replace($a,"//","/");
echo $b;
answered Nov 14 '13 at 11:53
John Ostrowick
6112
6112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f3145264%2fregular-expression-and-forward-slash%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown