0

Again:

 `string:  He will go b@rcelona today 
 $myvar:    [space here TOP Deletation]b'<== deletation begin'@'begin deletation==>rcelona[space here, TOP deletation]

Output: He will go today`

The example of the house is what happened to a file that I have to clean, it is very dirty, and its first code worked very well, but only with asterisks, different from the request of the question.

Here I do match with everything that is not alphanumeric:

^a-zA-Z0-9 

Here I do match with everything that is not alphanumeric: ^ a-zA-Z0-9 I need to clean everything that comes before it until the next empty space (blank space \s ... I do not know how to do it, I already I tried a lot on my own) until I delete everything that comes after the alpha numeric character, but what comes before it until the next blank? please: * = ALL Non-Alpha Numerics

[Stop in white space, leave it]888AAAA*AAAA888[white space]
Asterisk is representing any non-alpha character.(~^*&%$>>>)
I need find the * and clean it: * and everything that comes before or after and stop only while find first white space. 
    Exactly how it does: 
[^\s*]*\*([a-zA-Z0-9]*) But only works only with asterisks.

[^\s*]*\*([a-zA-Z0-9]*);

But I'm facing a case here in my work, that I need to do a big cleaner in several variables, but looking for "/[^a-zA-Z0-9\s]/" And everything I had glued to it

 I need this output with:
That is a big house mmmm&MmmMM pppp%MMMM hhhh!HHHH UUUU?000^uuuu~yyyy and very well localized 

 What else is non alpha numeric? "/[^a-zA-Z0-9\s]/"  or \W

 Every time I find a character not alpha numerical, delete everything forward and backward, stopping at the space:

[^\s*]*\*([a-zA-Z0-9]*)

Thanks agains.

Iori Sanch
  • 25
  • 7
  • 1
    What is that, don't understand your question ... it's mix of a mix of mix thing... please write the question properly... with sample input and output – Mustofa Rizwan Mar 05 '17 at 11:02
  • Your answer is here: http://stackoverflow.com/questions/659025/how-to-remove-non-alphanumeric-characters –  Mar 05 '17 at 11:02
  • Possible duplicate of [How to remove non-alphanumeric characters?](http://stackoverflow.com/questions/659025/how-to-remove-non-alphanumeric-characters) –  Mar 05 '17 at 11:03
  • do you need to retain the last whitespace? – RomanPerekhrest Mar 05 '17 at 11:05
  • @Fair Play This question has no relation with the removal of non-alphanumerical values, the issue here is a backwards, deleting what comes before until finding and respecting a common space. As a backspace of the screened before non-alpha numerical. – Iori Sanch Mar 05 '17 at 11:36
  • @RomanPerekhrest thanks for ask me :-) Yes I need to backspace before this asterisk and respect the next space found. Sorry I did not say it before. – Iori Sanch Mar 05 '17 at 11:37
  • show how should look the expected result for the exemplary input `" eD654*123Ab abc1#45 1 "` – RomanPerekhrest Mar 05 '17 at 11:47
  • I have edited my question :-) $output = '123Ab' Either clean or not symbol, this I know to turn, I want to know what comes before, Back actions. – Iori Sanch Mar 05 '17 at 11:55
  • it's still unclear, what if a special character is at the end: `" eD654123A b* "` ? – RomanPerekhrest Mar 05 '17 at 12:00
  • This is a complete variable: eD654*123Ab I want to delete half, from asterisk to back. this: eD654 and leave this: *123Ab in the variable – Iori Sanch Mar 05 '17 at 12:09
  • use `preg_replace('/^[^*]+/','',$s)` to remove up to the first asterisk. – Wiktor Stribiżew Mar 05 '17 at 13:09
  • That really not clear what you want. The last example says that you want to delete every thing that is not a digit after the first few words, is that what you want? It is contradictory with the first example where you want to delete all character before the first special. – Toto Mar 05 '17 at 17:18
  • Please re-edit you question with one line for input string and one line with expected result in a clear way. – Toto Mar 05 '17 at 17:19
  • @toto,  There is no contradiction here, I explain quite repeatedly, that I should delete and stop in the first blank [^\s]+ but I do not know how to do it back, as Rizman did(only wthin asteriscs, non interest for me, but the output was perfect). He did even better, forward and backward, stopping at the blank space found in the front: [^\s*]*\*([a-zA-Z0-9]*) = PERFECT, but I need with everyting non-alphanumeric. – Iori Sanch Mar 05 '17 at 17:48

1 Answers1

1

How about:

$input = 'That is a big house 1 mmmm&MmmMM 2 pppp%MMMM 3 hhhh!HHHH 4 UUUU?000^uuuu~yyyy';
$result = preg_replace('/(\d+\s)\S+/i', '$1', $input);
echo $result,"\n";

Output:

That is a big house 1  2  3  4 

Explanation:

/       : regex delimiter
  (     : start group 1
    \d+ : 1 or more digit
    \s  : a space
  )     : end group
  \S+   : 1 or more NON space character
/i      : regex delimiter, case insensitive
Toto
  • 89,455
  • 62
  • 89
  • 125
  • Thank you very much Toto for the explanation! I'll think a little bit now and see if I can work with it, create something for my case, because if I apply with those values ​​above, it works, but if I use it with other symbols, the command comes out doing too much, until whole sentences, the @Rizwan M.Tuman's code was almost perfect, it made the action perfect, but it only works with an asterisk and I do not know how to apply the all caracteres [^a-zA-Z0-9\s] on his code. – Iori Sanch Mar 05 '17 at 14:18
  • Hi @toko .. the code Rizman have a `perfect output: That is a big house 1 mmmm*MMMMM 2 pppp*MMMM 3 hhhh*HHHH 4 UUUU*000*uuuu*yyyy` `That is a big house 1 2 3` But I do not know how to adapt to my question, which is all the special characters, theirs back, their deleting is more than necessary, but their explanation is very good, I'm going to work with her here and I come back here. – Iori Sanch Mar 05 '17 at 14:35
  • @IoriSanch: Please, edit your question and add some test cases, some input strings and expected result for each one. The string you've given in previous comment doesn't do what you've explained in your question. – Toto Mar 05 '17 at 16:07
  • Exactly !! SOLVED absolutely :-) THANKS TO LOT !! A question that I can not go without doing, but I have never come across this thing srsrsrs because I have to use '$1 ' and not simple ' ' to occur cleaning without deleting the numbers? Because when I try to do ' ' the numbers go together! If I make you '$1 ' the exit comes out perfect! It's perfectly functional, I just wanted to learn this! Why this need not to use? – Iori Sanch Mar 05 '17 at 18:30
  • help me @Toto sorry me by Make you understand that the numbers between the AAAAAA&AAaaAA dirt were necessary, the numbers among the dirt, were for you to understand that the code would have to respect the spaces, and not leave cleaning overall, your code only has the perfect output like Rizman, If I put the numbers between each dirty string with symbols! They are just an example of respect for the blanks, and the scan for both sides should start over with each new dirty string with symbols, yours is 90%, missing the requirements of numbered fields! Amazing as you write in regex! – Iori Sanch Mar 05 '17 at 23:28
  • this car is amazing aaaa*aaaaa aaaa&bbbbbb xxxxxxx^zzzzzzz faster car, your output: this car is amazing faster car, perfect, but exclude numeration requeriment – Iori Sanch Mar 05 '17 at 23:40
  • Another thing, even if I put numbering, `your code is clearing the 'faster' This car is amazing 1 aaaa*aaaaa 2 aaaa&bbbbbb 3 xxxxxxx^zzzzzzz 4 faster car` But I think removing the requirement of numbering this behavior does not occur, his code that works only with asterisks, numbered or not, always leave 'this car is amazing 1 2 3 4 faster car' or 'this car is amazing faster car' if I do not dirty the Numbered code. – Iori Sanch Mar 05 '17 at 23:54
  • The main focus of the question is alpha numerics characters, not only numbers, if the string does not have numbers! She will not be clean! Your code requires numbering in the strings! And clearly the numbering was only put to show in the example that the deletion could not affect the spaces. Should stop at them, your code speaks of numbers \ d and if there are no numbers, it does not work! Please Looking my first example. Thanks – Iori Sanch Mar 06 '17 at 08:11
  • Sorry @Toto, really, I said, everything that comes before, but should stop in the first blank, and start looking again to delete again, and stop again, not delete all my variable completely, but the code Of Rizman that code he did not even understand, he gave me idea to do everything I need in a single code, I have code to clean later, he made one to clean before and after, but infrequently just asterisks. Let's clear all variables with non-alpha numeric. This code only works with numbered strings! – Iori Sanch Mar 06 '17 at 09:11