I need a regex which can basically check for space, line break etc after string.
So conditions are,
- Allow special characters
.,_,-,+inside the string i.e.@hello.world,@hello_world,@helloworld, etc. - Discard anything including special characters where there is no alpha-numeric string after them i.e.
@helloworld.<space>,@helloworld-<space>,@helloworld.?, etc. must be parsed as@helloworld
My existing RegEx is /@([A-Za-z0-9+_.-]+)/ which works perfectly Condition #1, but still there seems to be a problem Condition #2
I am using above RegEx in preg_replace()
Solution:
$str = preg_replace('#@[\w+.\-]+\b#', '[[$0]]', $str);
This works perfectly.
Tested with