Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preg replace till dot including that

I am having one line I have to replace that below is the line

/myhome/ishere/where/are.you.ha

Here I have a live regex

preg_match('/(.+\/)[^.]+(.+\.ha)/', $input_line, $output_array);

it results me live this

/myhome/ishere/where/.you.ha

But I need a answer like this

/myhome/ishere/where/you.ha

Please anyone help me to remove this dot.

like image 827
be MrZulf Avatar asked Jun 30 '26 02:06

be MrZulf


1 Answers

You can use

/^(.+\/)[^.]*\.(.*\.ha)$/

See the regex demo. Details:

  • ^ - start of a string
  • (.+\/) - Group 1: any one or more chars other than line break chars as many as possible and then /
  • [^.]* - zero or more chars other than a .
  • \. - a . char
  • (.*\.ha) - Group 2: any zero or more chars other than line break chars as many as possible and then .ha
  • $ - end of a string
like image 133
Wiktor Stribiżew Avatar answered Jul 01 '26 14:07

Wiktor Stribiżew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!