Translate

Friday, November 7, 2014

How to remove the letter of an alphanumeric string


How to remove the letter of an alphanumeric string



In this post, I'll  try to explain how to remove the letter of an alphanumerics string.Maybe this tutorial could be helpful for you :

we have the following code:



  $sMystring = 'Tra789asdf'; //1
  $pMypattern = '/[a-zA-z]/'; //2
  $sMyreplacement = ''; //3
  echo preg_replace($pMypattern, $sMyreplacement, $sMystring);//4
 

Code explanation:

First Line: We have our alphanumeric string ,I mean a combination between numbers and letters.

Second Line: We have out REGEX pattern, which identify the letter in our string $pMypattern.

Third  Line: We have a variable that will use to replace the letter, by that I mean instead of letter we  will have in the string blank spaces.

Fourth Line:  We will have our output and it is important to note the preg_replace
 which  identified in the string the pattern and remove the matches and replace with the new value in our case is: $Myreplacement.


Output : 789

If want the opposite output, I mean remove the number the code will be:
   

    $sMystring = 'Tra789asdf';//1
    $pMypattern = '/[0-9]/';//2
    $sMyreplacement = ''; //3
    echo preg_replace($pMypattern, $sMyreplacement, $sMystring); //4
 

Output :: Traasdf


La Gloria de Dios

La Gloria de Dios




LA GLORIA DE DIOS: La iglesia existe para exaltar la Gloria de Dios.
Dios es glorioso! y nosotros conocemos su Gloria por medio de la cruz, la naturaleza nos enseña acerca del ingenio de Dios, de su bondad, de su creatividad, hermosura,
Pero es la muerte de Jesús en la cruz y su resurrección la que nos enseña que Dios es Airado, pero a la vez Misericordioso, Justo pero a la vez Dios de Gracia, que es Santo pero a la vez Amor.... Por tanto, esta custodia de su gloria ante el mundo que Cristo nos dejó, ha quedado en manos de la iglesia... somos mayordomos de la gloria de Dios por medio de el evangelio, pero es necesario que nos mostremos fieles.

REGEX  :Identify Comma outside  Double Quotes







If  you want to identify each comma outside double quotes this is the regex:

(?!\B"[^"]*),(?![^"]*"\B)

Result:


but if you are using PHP the regex above  will not going to work ,so you can use this regex: 

Regex: (,)(?=(?:[^"]|"[^"]*")*$)

Result: