How to Write a Regex to Select Everything Between "Hello," and "Vehicle ID:" Including the First Phrase but Not the Second?

This topic was automatically generated from Slack. You can find the original thread here.

can you write a regex to select everything between “Hello,” and “Vehicle ID:“. Include the first phrase in the match, but stop before the second phrase.

markdown To create a regex that selects everything between "Hello," and "Vehicle ID:", including "Hello," but not including "Vehicle ID:", you can use the following pattern:  
```regex (Hello,.**?)(?=Vehicle ID:) ```
  This pattern uses a positive lookahead `(?=Vehicle ID:)` to assert that "Vehicle ID:" follows the matched text without including it in the match. The `.**?` is a non-greedy match that captures any characters between "Hello," and "Vehicle ID:". 

why isn’t this working for this paragraph? “Goodyear Hello, The service provider was unable to complete your service appointment by the estimated completion time due to Vehicle not on site. Please reschedule these services from the vehicle details page linked below. Vehicle ID: PONL21 Services: Oil Change Recommended Reschedule Date: Link to Vehicle Details”

It appears that you’re experiencing an issue with a specific text or workflow process related to Pipedream, but the details provided are not sufficient to understand the context or the exact problem you’re facing. Could you please provide more information about what you’re trying to achieve with Pipedream and the steps you’ve taken so far? This will help me assist you better. If you’re trying to parse or manipulate the given paragraph within a Pipedream workflow, please share the relevant code or component details.

when you say “Include the first phrase in the match, but stop before the second phrase.“, is there a specific character that consistently separates phrases?

It’d be just a space, or the specific word. Here’s the regex (of the second expression) working in regex101

gotcha, by include the first phrase but not the second did you mean include “Hello…” but not “Vehicle ID:“?

Correct

this code appeared to work for me:

export default defineComponent({
  async run({ steps, $ }) {
    const text = `Goodyear Hello, The service provider was unable to complete your service appointment by the estimated completion time due to Vehicle not on site. Please reschedule these services from the vehicle details page linked below. Vehicle ID: PONL21 Services: Oil Change Recommended Reschedule Date: Link to Vehicle Details`
    return text.match(/(Hello,.*?)(?=Vehicle ID:)/gsi)
  },
})

that returned

Hello, The service provider was unable to complete your service appointment by the estimated completion time due to Vehicle not on site. Please reschedule these services from the vehicle details page linked below.

does that look like what you expect?

That looks exactly like I expect. The original input looks below (note the line breaks), but when ran inside Pipedream it’s all condensed, so I assumed it’s removing all HTML tags.

No matches found

got it, to handle the line breaks you’ll need to add an s to the flags, so I modified the code example above to use

text.match(/(Hello,.*?)(?=Vehicle ID:)/gsi)

So that might work if you want to try the code, but what action are you using? I’ll see if we can also support the standard regex flags available in Node

but for now the code may be the best way to handle

Using the built-in formatting action.
Is there a way to add the flags to that action?

not right now but we can definitely modify it to support it! the “Extract by Regular Expression” formatting action doesn’t let me set flags on the regular expression. In this case we want to match the newline characters with the .*, so we need to pass the s flag to support that. I’m not sure if a single prop that lets me just pass the standard flags would be OK or if we should add props for each flag and make it a little more user-friendly, but wanted to raise.

Just tried with node, but how can I reference previous steps?

If you hover over the field you noted above (from this screenshot), you’ll see a Copy path button. That will copy a variable reference to that field that you can use in any step, e.g. steps.step_1.$return_value