Re: regex/preg_replace? How do I do this?



GoL,

You could use something like this:

preg_replace('/(\d{3})\d{3}(\d{4})/', '\1###\2', '1234567890');

where '1234567890' is your text. Depending on the format of your
input source, you may also need to specify the delimiter at the
beginning or end of the expression, but this will work for a plain
list of the 10-digit numbers.

I'd really advise you to read up on regular expressions. Strangely,
the TextMate book (http://www.pragmaticprogrammer.com/titles/
textmate/) really clarified them for me (if you're a mac user).

ethan

On Jun 4, 7:58 am, GoL <usenet@^^.wwwspace.net._nospam_^^> wrote:
Hi all,

I have a problem that I *think* is simple, but since I'm completely
ignorant about regex expression I don't have a clue how to do it...

What I need to do is to find all instances in a string where there are
exactly 10 digits in a row, and replace the 4th, 5th and 6th digit
with a # sign.
So if I have the string:

"some text here 1234567890 more text 0987654321 and more text"

I want it replaced with:

"some text here 123###7890 more text 098###4321 and more text"

How do I do this?
Greatful for any help.

Thanks,
/G

.



Relevant Pages

  • Re: Is it possible to Change String Delimiter without using an interface Spec?
    ... If you want to use TransferText the only way to specify a non-standard ... delimiter is by using an import specification or a schema.ini file. ... > the data has a ' as the string delimiter. ...
    (microsoft.public.access.externaldata)
  • Re: string manipulation function
    ... Recent versions of Access have a Splitfunction that allows you to specify ... In older versions, use Instr() to locate the delimiter, and Midto chop up ... > Is there a function allowing me to cut a string of characters separated by ...
    (microsoft.public.access.modulesdaovba)
  • Re: Importing from CSV file
    ... Yes, that imports each row as one long string, even when I ... specify the delimiter ...
    (comp.soft-sys.matlab)
  • Re: Programmers unpaid overtime.
    ... tokenizing a string correctly. ... ability to specify a set of delimiter tokens, ... >> postmodern attack on language itself, ... An the scientists, in turn, think a lot of that artistic talk about ...
    (comp.programming)
  • Re: Surprise in StrConv using vbProperCase
    ... > Your code will capitalize the first letter of a string. ... Use Split(string into array of words using blank as delimiter); ...
    (microsoft.public.access.modulesdaovba)