PHP regular expression


i have huge string that i need to separate information. Some parts of it vary and some dont. The difficulty i am facing is that i cant find a symbol or something on which i could get the match i want. So here is the string:

$str = "01;01;283;Póvoa do Vâle do Trigo;15315100 01;01;249;Alcafaz;;;;;;;;;;;3750;011;AGADÃO 01;01;2504;Caselho;;;;;;;;;;;3750;012;AGADÃO _ "15" '' ghdhghg AND IT CONTINUES

so if we look at the first part of the string (01;01;283;Póvoa do Vale do Trigo;15315100), what i want to stay with is:


and remove the rest of the stuff

in every case, but looking at the first example... : the 01 is always a number never superior to 2 (not 040 or 150505 or 4075) the same for the next 01 never superior to 2 (not 405 or 1565 or 425) then the 283 is the number that can be bigger, it varies (it can be 300 or 17581 or 40755794)

essentially in the end i want only the beginning of each part like:

01;01;283 01;01;249 01;01;2504 05,80,104258 94,76,56789124

sorry for any misspelling i am Portuguese

<hr />

i forget to say that this separated parts will then go to an array! so the regular expression should not match for example like this:

15315100 01;01;249

so i cant use .+ for example



Try this:


Should work.


Try the following. The regex is in the match_all line.

$str = "***01;01;283***;Póvoa do Vâle do Trigo;15315100 ***01;01;249***;Alcafaz;;;;;;;;;;;3750;011;AGADÃO "; preg_match_all("/\*\*\*[01][0-9];[01][0-9];[0-9]*\*\*\*.*?/", $str, $matches); print_r($matches);



<a href="http://regex101.com/r/yP9pD2" rel="nofollow">DEMO</a>

And maybe it would be easier to just get everything between ***XXX***


<a href="http://regex101.com/r/qE1cI6" rel="nofollow">DEMO</a>


  • Match last occurence of 4 digits htaccess rewrite
  • Title over group of subplots
  • How to recursively resolve symlinks without readlink or realpath?
  • DynamoDb “Query key condition not supported”
  • WCF Service Application returns 404 using WebGet
  • iOS background and images seem to not scale properly for retina display
  • Manually ending the IntentService worker thread
  • MVC In Html.Begin form need two buttons call different actions with all the values of the form
  • Manually close layer control window (javascript)
  • Capitalize a substring within a string
  • Text classification extract tags from text
  • How to pass a custom object in REST webservice
  • What's a better way to swap two argument values?
  • Remove every nth element from swift array
  • How to add plugin dependencies to pom.xml
  • WPF: Resize item size to have all items visible
  • Get count of created entries for each day
  • Routing in WCF data services
  • ELMAH: Can you set it up to email errors only remotely?
  • Create a multiple screen android application
  • Initialization section of the package
  • How to load Q library with Require.js?
  • Create registry key in 32-bit hive on x64 PC using Installshield 2012 LE - Avoid redirection
  • OpenGL - Object Transformations and VBOs
  • PHP + XML - how to rename and delete XML elements using SimpleXML or DOMDocument?
  • Responsive design method for collapsing a div
  • How to draw a line dynamically in android [duplicate]
  • Xamarin MonoAndroid Azure mobile service InsertAsync
  • Looking for good analogy/examples for monitor verses semaphore
  • Sending HTML Form Data to Spring REST Web Service
  • C# program and C++ DLL compiled for 32-bit system crash on 64-bit system
  • Authentication in Play! and RestEasy
  • Stop Bash Script if Hive Fails
  • jQuery ready not fired after rails link_to is clicked
  • With Hadoop, can I create a tasktracker on a machine that isn't running a datanode?
  • Bad request using file_get_contents for PUT request in PHP
  • Regex thinks I'm nesting, but I'm not
  • What is the “return” in scheme?
  • Matrix multiplication with MKL
  • How to disable jQuery.jplayer autoplay?