How to extract information via regular expression?

0

I have the following string:

adapter-UDP02_sistem10_a.log

How to extract the UDP02 excerpt via regular expression? The logic is: capture everything after the - (hyphen) and before the first _ (underline)

    
asked by anonymous 25.01.2018 / 21:04

1 answer

3

Use -(.*?)_ .

- Starts the selection from the hyphen

(.*?)_ Here the sign of ? will limit until the first occurrence of _

Demo
Demonstration with PHP
Demonstration with Java >

Demonstration with JavaScript

const regex = new RegExp("-(.*?)_");
const value = "adapter-UDP02_sistem10_a.log";

let result = value.match(regex);

console.log( result[1] );
    
25.01.2018 / 21:09