Re: REGEX help please



Defaultman wrote:
1) change a string of:
number\number\number to number/number/number

You don't have to use regexp to do this. Try this:

$var = str_replace('\\', '/', $var);

assuming $var contains the string you want to change.

2) change a string of:
numbers to digit/digit/digit

This you can du with chunk_split():

$var = chunk_split($var, 1, '/');

This puts a '/' between every character in $var AND in the end. So if you don't want the '/' in the end you can remove it with substr():

$var = substr($var, 0, -1);

Hope this is useful.

Zilla.
.



Relevant Pages

  • Re: Single backslash in a string. How??
    ... I want var to have the value "\foo" ... irb:003:0> puts var.length ... backslash character you entered as an actual character vs. treating it as an ...
    (comp.lang.ruby)
  • Re: Armenian, Sumerian, Burushaski, and Turkic languages
    ... - sort of a blank character, ... maybe it really is a Norwegian thing. ... Det var en liten gutt som gikk og græt og var så lei, ... med blanke ark og fargestifter tel. ...
    (sci.lang)
  • Re: javascript compression
    ... var RingBellOnFatalError = false; ... returns a string detailing the line and char position of default ... read a character from line buffer, ... // tokens - an array of predifined tokens ...
    (microsoft.public.scripting.jscript)
  • Re: Trying to limit input ot certain numbers
    ... " part is and were in the help files I can learn about it. ... If you want one character from a string, then use the array-access notation to extract just that one character: ...
    (alt.comp.lang.borland-delphi)
  • Re: Wrapping applications in Ruby
    ... $ cat run-counter.rb ... puts "Got3 #" ... Am I right in thinking that the popen block gets called every time a \n character is captured by the pipe? ...
    (comp.lang.ruby)