Regex in php to get rid of $ [closed]
I need to get rid of $ but leave anything between the brackets with a regex replace with php. to be more precises want to take out opening $ and closing and leave everything else as is in the string.
for example if i have a
string = "here is part one $anything453*@else inhere and here is part two"
I want to get a
string = here is part one anything453*@else inhere and here is part two
or if I have a
string = $
I want to get a blank string.
I tried this and get an empty string
$string =preg_replace('/$/', '', $string);
php regex
closed as too broad by Wiktor Stribiżew, MonkeyZeus, miken32, Patrick Q, Toto Nov 12 '18 at 19:37
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 5 more comments
I need to get rid of $ but leave anything between the brackets with a regex replace with php. to be more precises want to take out opening $ and closing and leave everything else as is in the string.
for example if i have a
string = "here is part one $anything453*@else inhere and here is part two"
I want to get a
string = here is part one anything453*@else inhere and here is part two
or if I have a
string = $
I want to get a blank string.
I tried this and get an empty string
$string =preg_replace('/$/', '', $string);
php regex
closed as too broad by Wiktor Stribiżew, MonkeyZeus, miken32, Patrick Q, Toto Nov 12 '18 at 19:37
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Can you please post an actual example and what you have tried so far?
– user3783243
Nov 12 '18 at 17:58
1
You should edit your question to include a sample string of data and the result set of matches which you need. If possible, also include what regex you have tried and explain which part fails. As it stands, this question is too broad.
– MonkeyZeus
Nov 12 '18 at 17:59
1
Do you ever expect multiple instances of$
such as$string = '$tihs and $that';
? Or what would you expect from$string = 'hey there $something';
. Or what if$
is not the first character like$string = ' hello $hey 9frfg';
– MonkeyZeus
Nov 12 '18 at 18:11
What should happen with$string = 'some text here$this thing $another thing more text';
?
– MonkeyZeus
Nov 12 '18 at 18:26
1
@Diana What does "go away" mean? You should add my examples to your question and present the expected output. Why does this have to be a game of pulling teeth?
– MonkeyZeus
Nov 12 '18 at 18:36
|
show 5 more comments
I need to get rid of $ but leave anything between the brackets with a regex replace with php. to be more precises want to take out opening $ and closing and leave everything else as is in the string.
for example if i have a
string = "here is part one $anything453*@else inhere and here is part two"
I want to get a
string = here is part one anything453*@else inhere and here is part two
or if I have a
string = $
I want to get a blank string.
I tried this and get an empty string
$string =preg_replace('/$/', '', $string);
php regex
I need to get rid of $ but leave anything between the brackets with a regex replace with php. to be more precises want to take out opening $ and closing and leave everything else as is in the string.
for example if i have a
string = "here is part one $anything453*@else inhere and here is part two"
I want to get a
string = here is part one anything453*@else inhere and here is part two
or if I have a
string = $
I want to get a blank string.
I tried this and get an empty string
$string =preg_replace('/$/', '', $string);
php regex
php regex
edited Nov 12 '18 at 18:44
Diana
asked Nov 12 '18 at 17:56
DianaDiana
190314
190314
closed as too broad by Wiktor Stribiżew, MonkeyZeus, miken32, Patrick Q, Toto Nov 12 '18 at 19:37
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Wiktor Stribiżew, MonkeyZeus, miken32, Patrick Q, Toto Nov 12 '18 at 19:37
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
1
Can you please post an actual example and what you have tried so far?
– user3783243
Nov 12 '18 at 17:58
1
You should edit your question to include a sample string of data and the result set of matches which you need. If possible, also include what regex you have tried and explain which part fails. As it stands, this question is too broad.
– MonkeyZeus
Nov 12 '18 at 17:59
1
Do you ever expect multiple instances of$
such as$string = '$tihs and $that';
? Or what would you expect from$string = 'hey there $something';
. Or what if$
is not the first character like$string = ' hello $hey 9frfg';
– MonkeyZeus
Nov 12 '18 at 18:11
What should happen with$string = 'some text here$this thing $another thing more text';
?
– MonkeyZeus
Nov 12 '18 at 18:26
1
@Diana What does "go away" mean? You should add my examples to your question and present the expected output. Why does this have to be a game of pulling teeth?
– MonkeyZeus
Nov 12 '18 at 18:36
|
show 5 more comments
1
Can you please post an actual example and what you have tried so far?
– user3783243
Nov 12 '18 at 17:58
1
You should edit your question to include a sample string of data and the result set of matches which you need. If possible, also include what regex you have tried and explain which part fails. As it stands, this question is too broad.
– MonkeyZeus
Nov 12 '18 at 17:59
1
Do you ever expect multiple instances of$
such as$string = '$tihs and $that';
? Or what would you expect from$string = 'hey there $something';
. Or what if$
is not the first character like$string = ' hello $hey 9frfg';
– MonkeyZeus
Nov 12 '18 at 18:11
What should happen with$string = 'some text here$this thing $another thing more text';
?
– MonkeyZeus
Nov 12 '18 at 18:26
1
@Diana What does "go away" mean? You should add my examples to your question and present the expected output. Why does this have to be a game of pulling teeth?
– MonkeyZeus
Nov 12 '18 at 18:36
1
1
Can you please post an actual example and what you have tried so far?
– user3783243
Nov 12 '18 at 17:58
Can you please post an actual example and what you have tried so far?
– user3783243
Nov 12 '18 at 17:58
1
1
You should edit your question to include a sample string of data and the result set of matches which you need. If possible, also include what regex you have tried and explain which part fails. As it stands, this question is too broad.
– MonkeyZeus
Nov 12 '18 at 17:59
You should edit your question to include a sample string of data and the result set of matches which you need. If possible, also include what regex you have tried and explain which part fails. As it stands, this question is too broad.
– MonkeyZeus
Nov 12 '18 at 17:59
1
1
Do you ever expect multiple instances of
$
such as $string = '$tihs and $that';
? Or what would you expect from $string = 'hey there $something';
. Or what if $
is not the first character like $string = ' hello $hey 9frfg';
– MonkeyZeus
Nov 12 '18 at 18:11
Do you ever expect multiple instances of
$
such as $string = '$tihs and $that';
? Or what would you expect from $string = 'hey there $something';
. Or what if $
is not the first character like $string = ' hello $hey 9frfg';
– MonkeyZeus
Nov 12 '18 at 18:11
What should happen with
$string = 'some text here$this thing $another thing more text';
?– MonkeyZeus
Nov 12 '18 at 18:26
What should happen with
$string = 'some text here$this thing $another thing more text';
?– MonkeyZeus
Nov 12 '18 at 18:26
1
1
@Diana What does "go away" mean? You should add my examples to your question and present the expected output. Why does this have to be a game of pulling teeth?
– MonkeyZeus
Nov 12 '18 at 18:36
@Diana What does "go away" mean? You should add my examples to your question and present the expected output. Why does this have to be a game of pulling teeth?
– MonkeyZeus
Nov 12 '18 at 18:36
|
show 5 more comments
1 Answer
1
active
oldest
votes
If you want to remove $ and from string, you should use alternation in regex and use this,
$
and replace it with empty string.
Try this sample PHP code,
$str = 'here is part one $anything453*@else inhere and here is part two';
$str = preg_replace('/$/', '', $str);
echo $str;
This outputs following string,
here is part one anything453*@else inhere and here is part two
I know this question can be broad as you haven't mentioned what should happen in various possible cases, so if you want specific cases to be dealt particularly in specific ways, please add more examples for input string vs expected output string.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to remove $ and from string, you should use alternation in regex and use this,
$
and replace it with empty string.
Try this sample PHP code,
$str = 'here is part one $anything453*@else inhere and here is part two';
$str = preg_replace('/$/', '', $str);
echo $str;
This outputs following string,
here is part one anything453*@else inhere and here is part two
I know this question can be broad as you haven't mentioned what should happen in various possible cases, so if you want specific cases to be dealt particularly in specific ways, please add more examples for input string vs expected output string.
add a comment |
If you want to remove $ and from string, you should use alternation in regex and use this,
$
and replace it with empty string.
Try this sample PHP code,
$str = 'here is part one $anything453*@else inhere and here is part two';
$str = preg_replace('/$/', '', $str);
echo $str;
This outputs following string,
here is part one anything453*@else inhere and here is part two
I know this question can be broad as you haven't mentioned what should happen in various possible cases, so if you want specific cases to be dealt particularly in specific ways, please add more examples for input string vs expected output string.
add a comment |
If you want to remove $ and from string, you should use alternation in regex and use this,
$
and replace it with empty string.
Try this sample PHP code,
$str = 'here is part one $anything453*@else inhere and here is part two';
$str = preg_replace('/$/', '', $str);
echo $str;
This outputs following string,
here is part one anything453*@else inhere and here is part two
I know this question can be broad as you haven't mentioned what should happen in various possible cases, so if you want specific cases to be dealt particularly in specific ways, please add more examples for input string vs expected output string.
If you want to remove $ and from string, you should use alternation in regex and use this,
$
and replace it with empty string.
Try this sample PHP code,
$str = 'here is part one $anything453*@else inhere and here is part two';
$str = preg_replace('/$/', '', $str);
echo $str;
This outputs following string,
here is part one anything453*@else inhere and here is part two
I know this question can be broad as you haven't mentioned what should happen in various possible cases, so if you want specific cases to be dealt particularly in specific ways, please add more examples for input string vs expected output string.
edited Nov 12 '18 at 19:06
answered Nov 12 '18 at 19:00
Pushpesh Kumar RajwanshiPushpesh Kumar Rajwanshi
6,1082827
6,1082827
add a comment |
add a comment |
1
Can you please post an actual example and what you have tried so far?
– user3783243
Nov 12 '18 at 17:58
1
You should edit your question to include a sample string of data and the result set of matches which you need. If possible, also include what regex you have tried and explain which part fails. As it stands, this question is too broad.
– MonkeyZeus
Nov 12 '18 at 17:59
1
Do you ever expect multiple instances of
$
such as$string = '$tihs and $that';
? Or what would you expect from$string = 'hey there $something';
. Or what if$
is not the first character like$string = ' hello $hey 9frfg';
– MonkeyZeus
Nov 12 '18 at 18:11
What should happen with
$string = 'some text here$this thing $another thing more text';
?– MonkeyZeus
Nov 12 '18 at 18:26
1
@Diana What does "go away" mean? You should add my examples to your question and present the expected output. Why does this have to be a game of pulling teeth?
– MonkeyZeus
Nov 12 '18 at 18:36