I am wanting to change words in a string that has special tags.
Ex. "This is a %/i%special%i% word in the string."
If I want to replace any word between the %/i% and %i% what would I do?
I messed with preg_repace but I couldn't understand the pattern system.
Mike
|
|
0
|
|
|
|
Reply
|
null5451 (36)
|
7/11/2012 10:35:01 PM |
|
..oO(Michael Joel)
>I am wanting to change words in a string that has special tags.
>Ex. "This is a %/i%special%i% word in the string."
>If I want to replace any word between the %/i% and %i% what would I do?
>
>I messed with preg_repace but I couldn't understand the pattern system.
What have you tried so far? Do you have any experiences with regular
expressions?
Micha
--
http://mfesser.de/
Fotos | Blog | Flohmarkt
|
|
0
|
|
|
|
Reply
|
netizen9200 (1825)
|
7/11/2012 10:49:40 PM
|
|
Michael Fesser wrote:
> .oO(Michael Joel)
>
>
>>I am wanting to change words in a string that has special tags.
>>Ex. "This is a %/i%special%i% word in the string."
>>If I want to replace any word between the %/i% and %i% what would I do?
>>
>>I messed with preg_repace but I couldn't understand the pattern system.
>
>
> What have you tried so far? Do you have any experiences with regular
> expressions?
>
> Micha
>
I have tried many things but all return errors - mostly "unknown modifier".
Mike
|
|
0
|
|
|
|
Reply
|
null5451 (36)
|
7/11/2012 11:11:14 PM
|
|
Michael Fesser wrote:
> .oO(Michael Joel)
>
>
>>I am wanting to change words in a string that has special tags.
>>Ex. "This is a %/i%special%i% word in the string."
>>If I want to replace any word between the %/i% and %i% what would I do?
>>
>>I messed with preg_repace but I couldn't understand the pattern system.
>
>
> What have you tried so far? Do you have any experiences with regular
> expressions?
>
> Micha
>
answer to your last question - No
|
|
0
|
|
|
|
Reply
|
null5451 (36)
|
7/11/2012 11:11:59 PM
|
|
..oO(Michael Joel)
>Michael Fesser wrote:
>
>> .oO(Michael Joel)
>>
>>
>>>I am wanting to change words in a string that has special tags.
>>>Ex. "This is a %/i%special%i% word in the string."
>>>If I want to replace any word between the %/i% and %i% what would I do?
>>>
>>>I messed with preg_repace but I couldn't understand the pattern system.
>>
>>
>> What have you tried so far? Do you have any experiences with regular
>> expressions?
>>
>> Micha
>>
>
>I have tried many things but all return errors - mostly "unknown modifier".
Which means syntax error.
Please post your code.
Micha
--
http://mfesser.de/
Fotos | Blog | Flohmarkt
|
|
0
|
|
|
|
Reply
|
netizen9200 (1825)
|
7/11/2012 11:26:10 PM
|
|
Michael Fesser wrote:
> .oO(Michael Joel)
>
>
>>Michael Fesser wrote:
>>
>>
>>>.oO(Michael Joel)
>>>
>>>
>>>
>>>>I am wanting to change words in a string that has special tags.
>>>>Ex. "This is a %/i%special%i% word in the string."
>>>>If I want to replace any word between the %/i% and %i% what would I do?
>>>>
>>>>I messed with preg_repace but I couldn't understand the pattern system.
>>>
>>>
>>>What have you tried so far? Do you have any experiences with regular
>>>expressions?
>>>
>>>Micha
>>>
>>
>>I have tried many things but all return errors - mostly "unknown modifier".
>
>
> Which means syntax error.
>
> Please post your code.
>
> Micha
>
I was trying to just first get it to replace the exact thing typed. Then
move on to replacing any word within the %/i% and %i%
$Scripture="this is a %/i%test%i%";
preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
This errors with Unknown modifier t
I tried what I thought was escaping it by putting a \test but that just
messes up more. See I haven't a clue.
Mike
|
|
0
|
|
|
|
Reply
|
null5451 (36)
|
7/11/2012 11:31:12 PM
|
|
--Sig_/HyCZvLANpVaUz1m1Qy31s3H
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable
In article <V5KdnVyG6ph9kWPSnZ2dnUVZ_uWdnZ2d@earthlink.com>,
Michael Joel <null@void.void> wrote:
> Michael Fesser wrote:
>>=20
>> .oO(Michael Joel)
>>>=20
>>> Michael Fesser wrote:
>>>>=20
>>>> .oO(Michael Joel)
>>>>>
>>>>> I am wanting to change words in a string that has special tags.
>>>>> Ex. "This is a %/i%special%i% word in the string."
>>>>> If I want to replace any word between the %/i% and %i% what would I d=
o?
>>>>>=20
>>>>> I messed with preg_repace but I couldn't understand the pattern syste=
m.
>>>>
>>>> What have you tried so far? Do you have any experiences with regular
>>>> expressions?
>>>=20
>>> I have tried many things but all return errors - mostly "unknown modifi=
er".
>>=20
>> Which means syntax error.
>>=20
>> Please post your code.
>
> I was trying to just first get it to replace the exact thing typed. Then=
=20
> move on to replacing any word within the %/i% and %i%
>=20
> $Scripture=3D"this is a %/i%test%i%";
> preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
[url] http://php.net/manual/en/regexp.reference.delimiters.php [/url]
preg_replace("#%/i%test%i%#","XXXXXXXX",$Scripture);
=20
> This errors with Unknown modifier t
> I tried what I thought was escaping it by putting a \test but that just=20
> messes up more. See I haven't a clue.
--=20
BootNic Wed Jul 11, 2012 09:3=
2 pm
When I was young, I was put in a school for retarded kids for two years b=
efore
they realized I actually had a hearing loss...and they called ME slow!
*Kathy Buckley*
--Sig_/HyCZvLANpVaUz1m1Qy31s3H
Content-Type: application/pgp-signature; name=signature.asc
Content-Disposition: attachment; filename=signature.asc
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
iEYEARECAAYFAk/+KUQACgkQOcdbyBqMFBHQxQCdEjx1NAH5qK01lZZLUsXm7lG7
pOQAn25iqK4vBB+Lo0iZOc/39yC0o+ZZ
=moME
-----END PGP SIGNATURE-----
--Sig_/HyCZvLANpVaUz1m1Qy31s3H--
|
|
0
|
|
|
|
Reply
|
bootnic.bounce (10)
|
7/12/2012 1:32:52 AM
|
|
Michael Joel wrote:
> I am wanting to change words in a string that has special tags.
> Ex. "This is a %/i%special%i% word in the string."
> If I want to replace any word between the %/i% and %i% what would I do?
>
> I messed with preg_repace but I couldn't understand the pattern system.
>
> Mike
Since this function seems to elude me I simply wrote a samll function to
do what I want. I simply pass it the two needles, haystack and what I
want to replace with.
Thanks
Mike
|
|
0
|
|
|
|
Reply
|
null5451 (36)
|
7/12/2012 3:27:40 AM
|
|
On Wed, 11 Jul 2012 19:31:12 -0400, Michael Joel wrote:
> I was trying to just first get it to replace the exact thing typed. Then
> move on to replacing any word within the %/i% and %i%
>
> $Scripture="this is a %/i%test%i%";
> preg_replace("%/i%test%i%","XXXXXXXX",$Scripture);
>
> This errors with Unknown modifier t I tried what I thought was escaping
> it by putting a \test but that just messes up more. See I haven't a
> clue.
http://php.net/manual/en/regexp.reference.delimiters.php
When you use a regex, the first character inside your quotes is taken as
the pattern delimiter.
In your case, this is a "%" character.
The format of a regex string is:
"delimiter pattern delimiter optional-modifiers"
Hence, "%/i%t" is the pattern "/i" with the modifier "t"
Try:
preg_replace("!%/i%test%i%!","XXXXXXXX",$Scripture);
This will use the "!" character as the pattern delimiter and should, in
this specific case, solve your problem. Generally it's a good idea to
pick a pattern delimiter that does not have special meaning to regex and
is not part of your data. This isn't always easy.
Rgds
Denis McMahon
|
|
0
|
|
|
|
Reply
|
denismfmcmahon (354)
|
7/13/2012 3:22:07 AM
|
|
|
8 Replies
33 Views
(page loaded in 0.125 seconds)
Similiar Articles: perl + regex bug? - comp.lang.perl.misc... some reason, without the $index--; $index++; business, my second pattern is not matching ... m ok with the workaround. but if there's something that i'm not understanding ... gawk problem matching multiple patterns ?!? HOW-TO? - comp.lang ...I suppose that to understand why my original RE didn't work, > and yours did, I ... Join two lines in pattern matching, search, then assign fields to ... gawk problem ... Regex to match a numerical IP range - comp.lang.perl.misc ...... the post from perl.beginners: " For a reason i don't understand: 127.0.0.1 doesn't match ... Join two lines in pattern matching, search, then assign fields to ... ... Generating all possible combinations of a 5 digit pattern. - comp ...... of frames is a laborious task at the least and the big problem with pattern matching ... If you would care to elaborate more on your example, that might help me understand ... What software to render a bead or tile pattern from a scan? - comp ...... are wider, or taller because beads do not necessarily fit a square pattern. ... eyes, or other details can be made to match ... I could explain my imperfect understanding, but ... /etc/project user-list format - comp.unix.solarisI assume that such a pattern won't match pczzzz but I need to be sure. ... to" > dpc* > tpc* > ppc* > xpc* > > pc* !=3D pczzzz Thanks - I understand what ... Two 8086 Assembly Language Questions.. - comp.lang.asm.x86 ...If you really need to do it as string processing, try using HLA's pattern matching ... How to perform division ? - comp.lang.asm.x86 Dear Sir, As I understand assembly ... Script to count occurrences - comp.unix.programmerDo I not understand something? Generate 15000000 random ipa's, only 10000 unique. ... to count occurrences - comp.unix ... only one level of "automatic" pattern matching ... remove junk characters - comp.lang.perl.miscInside child ... recursion you must first understand recursion. Remove ... Instead ... vim - comp.unix.admin I want to delete ... comp.lang.awk Categories of pattern matching ... print columns from bash variable - comp.lang.awk... as I'd expect, but repeats all the columns afterwards, and I don't understand why. ... Join two lines in pattern matching, search, then assign fields to ... print columns from ... Pattern Matching with Regular Expressions - lauralemay :: workUnderstanding pattern matching and regular expressions and why you'll find them ... but the y can appear any number of times including not at all. This pattern will match ... Categories of pattern matching charactersPattern-matching characters can be grouped into various categories, which will be explained in detail later. By understanding these characters, you ... 7/17/2012 10:30:15 AM
|