-2

I want to match words with underscore from line

Example:

<span style="font-size: 10pt;line-height: 1.5;">K_Snsr_PsuMi_WdgVoltRef = 0.0007</span><br/>
        <span style="font-size: 10pt;line-height: 1.5;">- K_Snsr_PsuMisc_WdgVol = 0</span><br/>

From above should match below words:

K_Snsr_PsuMi_WdgVoltRef
K_Snsr_PsuMisc_WdgVol

Please help in achieving this.

InSync
  • 4,851
  • 4
  • 8
  • 30
  • 1
    HTML shouldn't be parsed with [regex](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454) – DarkBee Jul 19 '23 at 06:04
  • 1
    What are the rules? This:`i_Am` _"are words with underscore"_ – Flydog57 Jul 19 '23 at 06:20

2 Answers2

0

this will match if it always starts with a letter \w+_[\w_]*

tallberg
  • 429
  • 3
  • 12
0

Here is an example in js:

function findWordsWithUnderscore(text) {
  const regex = /\b\w+_\w+\b/g;
  const words = text.match(regex);
  return words;
}

const text = `<span style="font-size: 10pt;line-height: 1.5;">K_Snsr_PsuMi_WdgVoltRef = 0.0007</span><br/>
        <span style="font-size: 10pt;line-height: 1.5;">- K_Snsr_PsuMisc_WdgVol = 0</span><br/>`;

const result = findWordsWithUnderscore(text);
console.log(result);
Efros Ionelu
  • 226
  • 7