regular expression and forward slash










17














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.










share|improve this question


























    17














    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.










    share|improve this question
























      17












      17








      17


      5





      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.










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jun 29 '10 at 22:32









      pixeline

      15.2k87295




      15.2k87295






















          4 Answers
          4






          active

          oldest

          votes


















          36














          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/






          share|improve this answer






















          • 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


















          2














          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





          share|improve this answer




























            0














            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.






            share|improve this answer




























              0














              this should work:



              $a="Hello////////"; 
              $b=str_replace($a,"//","/");
              echo $b;





              share|improve this answer




















                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
                );



                );













                draft saved

                draft discarded


















                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









                36














                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/






                share|improve this answer






















                • 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















                36














                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/






                share|improve this answer






















                • 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













                36












                36








                36






                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/






                share|improve this answer














                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/







                share|improve this answer














                share|improve this answer



                share|improve this answer








                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
















                • 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













                2














                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





                share|improve this answer

























                  2














                  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





                  share|improve this answer























                    2












                    2








                    2






                    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





                    share|improve this answer












                    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






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jun 29 '10 at 22:41









                    nathan

                    4,52611618




                    4,52611618





















                        0














                        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.






                        share|improve this answer

























                          0














                          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.






                          share|improve this answer























                            0












                            0








                            0






                            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.






                            share|improve this answer












                            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.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jun 29 '10 at 22:39









                            Ian Wood

                            5,25352767




                            5,25352767





















                                0














                                this should work:



                                $a="Hello////////"; 
                                $b=str_replace($a,"//","/");
                                echo $b;





                                share|improve this answer

























                                  0














                                  this should work:



                                  $a="Hello////////"; 
                                  $b=str_replace($a,"//","/");
                                  echo $b;





                                  share|improve this answer























                                    0












                                    0








                                    0






                                    this should work:



                                    $a="Hello////////"; 
                                    $b=str_replace($a,"//","/");
                                    echo $b;





                                    share|improve this answer












                                    this should work:



                                    $a="Hello////////"; 
                                    $b=str_replace($a,"//","/");
                                    echo $b;






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Nov 14 '13 at 11:53









                                    John Ostrowick

                                    6112




                                    6112



























                                        draft saved

                                        draft discarded
















































                                        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.




                                        draft saved


                                        draft discarded














                                        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





















































                                        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







                                        Popular posts from this blog

                                        Top Tejano songwriter Luis Silva dead of heart attack at 64

                                        ReactJS Fetched API data displays live - need Data displayed static

                                        政党