Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Regular Expressions
  4. Help for a regexp

Help for a regexp

Scheduled Pinned Locked Moved Regular Expressions
pythontoolsregexhelptutorial
3 Posts 2 Posters 19 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_16168304
    wrote on last edited by
    #1

    Good morning I need to "purify" sentences to be able to use them in an app. Thanks a lot for your help in helping me build the right code :) I think the pattern is: - 'any sentence' (0 or 1 time) {text here} (0-N times) example AB CD {xxxxx} or AB CD {xxxxx,yyyy} or {xxxxx} or AB CD or AB CD {xxxxx} AB CD {xxxxx} or AB CD {xxxxx} {xxxxx} {xxxxx} etc - the {text here} block looks like {digit|some text}. For example: {1|xxxxxxxxx} - the 'some text' block can (not mandatory) contain 'default=xxx' at any place in the text ex: {3|abc=d,default=my value} or {2|a b c=d,default=my value,another=valueThatIDontNeed} or {1|default=my value} I need to isolate the following parts and return them to a string. - 'any sentence' text (if exists) - xxx of the 'default=xxx' pattern, as per above explanation This does not need to be done in one pass, I can script that in loops in Python for example. Here are a few examples Example 1 Store bulk masses greater than {0|message=|filter=^(_)?MASS_VALUE.+|add space after=false.+}{1|message=|filter=^(_)?P413_MASS_UNIT.+} at temperatures not exceeding {2|message=|filter=^(_)?TEMP_VALUE_.+|add space after=false.+}{3|message=|filter=^(_)?P413_TEMP_UNIT_.+} this should give Store bulk masses greater than at temperatures not exceeding Example 2 Inhoud onder {0|message=|default=inert gas|filter=^(_)?P231_STORAGE_.+} gebruiken en bewaren. Tegen vocht beschermen. Should give Inhoud onder inert gas gebruiken en bewaren. Tegen vocht beschermen. Example 3 EN CAS DE CONTACT AVEC LA PEAU: Laver abondamment{0|message=|default=à l’eau|filter=^(_)?P352_WASH_.+}. Appeler immédiatement {1|message=|default=un CENTRE ANTIPOISON ou un médecin|filter=^(_)?P310_EMERGENCY_.+}. Should give EN CAS DE CONTACT AVEC LA PEAU: Laver abondamment à l’eau . Appeler immédiatement un CENTRE ANTIPOISON ou un médecin Example 4 {0|message=|default=Inhoud/verpakking|filter=^(_)?P501_REQUIREMENT_.+} afvoeren naar {1|message=|default=…|filter=^(_)?P501_DISPOSAL_.+}. Should give Inhoud/verpakking

    M S 2 Replies Last reply
    0
    • M Member_16168304

      Good morning I need to "purify" sentences to be able to use them in an app. Thanks a lot for your help in helping me build the right code :) I think the pattern is: - 'any sentence' (0 or 1 time) {text here} (0-N times) example AB CD {xxxxx} or AB CD {xxxxx,yyyy} or {xxxxx} or AB CD or AB CD {xxxxx} AB CD {xxxxx} or AB CD {xxxxx} {xxxxx} {xxxxx} etc - the {text here} block looks like {digit|some text}. For example: {1|xxxxxxxxx} - the 'some text' block can (not mandatory) contain 'default=xxx' at any place in the text ex: {3|abc=d,default=my value} or {2|a b c=d,default=my value,another=valueThatIDontNeed} or {1|default=my value} I need to isolate the following parts and return them to a string. - 'any sentence' text (if exists) - xxx of the 'default=xxx' pattern, as per above explanation This does not need to be done in one pass, I can script that in loops in Python for example. Here are a few examples Example 1 Store bulk masses greater than {0|message=|filter=^(_)?MASS_VALUE.+|add space after=false.+}{1|message=|filter=^(_)?P413_MASS_UNIT.+} at temperatures not exceeding {2|message=|filter=^(_)?TEMP_VALUE_.+|add space after=false.+}{3|message=|filter=^(_)?P413_TEMP_UNIT_.+} this should give Store bulk masses greater than at temperatures not exceeding Example 2 Inhoud onder {0|message=|default=inert gas|filter=^(_)?P231_STORAGE_.+} gebruiken en bewaren. Tegen vocht beschermen. Should give Inhoud onder inert gas gebruiken en bewaren. Tegen vocht beschermen. Example 3 EN CAS DE CONTACT AVEC LA PEAU: Laver abondamment{0|message=|default=à l’eau|filter=^(_)?P352_WASH_.+}. Appeler immédiatement {1|message=|default=un CENTRE ANTIPOISON ou un médecin|filter=^(_)?P310_EMERGENCY_.+}. Should give EN CAS DE CONTACT AVEC LA PEAU: Laver abondamment à l’eau . Appeler immédiatement un CENTRE ANTIPOISON ou un médecin Example 4 {0|message=|default=Inhoud/verpakking|filter=^(_)?P501_REQUIREMENT_.+} afvoeren naar {1|message=|default=…|filter=^(_)?P501_DISPOSAL_.+}. Should give Inhoud/verpakking

      M Offline
      M Offline
      Member_16168304
      wrote on last edited by
      #2

      I've been able to isolate text vs {} blocks in RegExr: Learn, Build, & Test RegEx[^] and Regex Tester and Debugger Online - Javascript, PCRE, PHP[^] using

      ((?![{}])\w| )*|(({.*?}))

      I'd then expert to use a python or php script to loop on groups , and for each group launch another regex to grep the "default=xxx" text only. but using the same regex in python does not work :(:( The regex does not isolate block the same way as the 2 websites do :( Looking for a bit of help here :) Thanks so much

      1 Reply Last reply
      0
      • M Member_16168304

        Good morning I need to "purify" sentences to be able to use them in an app. Thanks a lot for your help in helping me build the right code :) I think the pattern is: - 'any sentence' (0 or 1 time) {text here} (0-N times) example AB CD {xxxxx} or AB CD {xxxxx,yyyy} or {xxxxx} or AB CD or AB CD {xxxxx} AB CD {xxxxx} or AB CD {xxxxx} {xxxxx} {xxxxx} etc - the {text here} block looks like {digit|some text}. For example: {1|xxxxxxxxx} - the 'some text' block can (not mandatory) contain 'default=xxx' at any place in the text ex: {3|abc=d,default=my value} or {2|a b c=d,default=my value,another=valueThatIDontNeed} or {1|default=my value} I need to isolate the following parts and return them to a string. - 'any sentence' text (if exists) - xxx of the 'default=xxx' pattern, as per above explanation This does not need to be done in one pass, I can script that in loops in Python for example. Here are a few examples Example 1 Store bulk masses greater than {0|message=|filter=^(_)?MASS_VALUE.+|add space after=false.+}{1|message=|filter=^(_)?P413_MASS_UNIT.+} at temperatures not exceeding {2|message=|filter=^(_)?TEMP_VALUE_.+|add space after=false.+}{3|message=|filter=^(_)?P413_TEMP_UNIT_.+} this should give Store bulk masses greater than at temperatures not exceeding Example 2 Inhoud onder {0|message=|default=inert gas|filter=^(_)?P231_STORAGE_.+} gebruiken en bewaren. Tegen vocht beschermen. Should give Inhoud onder inert gas gebruiken en bewaren. Tegen vocht beschermen. Example 3 EN CAS DE CONTACT AVEC LA PEAU: Laver abondamment{0|message=|default=à l’eau|filter=^(_)?P352_WASH_.+}. Appeler immédiatement {1|message=|default=un CENTRE ANTIPOISON ou un médecin|filter=^(_)?P310_EMERGENCY_.+}. Should give EN CAS DE CONTACT AVEC LA PEAU: Laver abondamment à l’eau . Appeler immédiatement un CENTRE ANTIPOISON ou un médecin Example 4 {0|message=|default=Inhoud/verpakking|filter=^(_)?P501_REQUIREMENT_.+} afvoeren naar {1|message=|default=…|filter=^(_)?P501_DISPOSAL_.+}. Should give Inhoud/verpakking

        S Offline
        S Offline
        Sernjijj Kabral
        wrote on last edited by
        #3

        Yes, based on kernel it's true.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups