Skip to content

Tag: regex

Getting zipcode from a string

I am trying to get zipcodes out of address strings. Zipcodes may look like this: 23-123 or 50-530. Strings usually look like this: Street 50, 50-123 City What I tried to do is finding the position of the zipcode and cut the next 6 characters starting from that point. Unfortunatelly strpos returns false all th…

How to remove specific html tags with contents in php?

I have some contents in string format include some unwanted html tags and its content. I am looking for a way to remove them but still could not find a perfect solution for the purpose. Method 1 Normally, we use strip_tags to remove the tags but it reserves the text content inside the tag. Method 2 Then I tri…

(REGEX) Replace with empty when two appear in a string PHP

i have differents strings may be can: 1 Case 2 Case 3 Case I’m try to limit to In cases if have found 3 or more continue With the php code: Expected cases: 1 Case 2 Case 3 Case Used regex: Testing: https://paiza.io/projects/sLcZE5fW99p3gfrxaZGDsg Thanks My Regex not working Answer If you want to replace…

RegEx not matching all required chars. What did I do wrong?

I want to allow inputs like _X_C or _X_X_X with the following regex: The following should be allowed only once: _X_C _X_L _L or … _X_X_X (0 to threetimes) The only thing that does not work is the allowance of “_X_X_X” or even “_X” What did I do wrong? Answer You may use See the r…

How to get specific (unique code) word from string on php? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed last year. Improve this question I have text string like : [CLOSED][#SD_1623834126_001] lorem ipsum ? and que…