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)
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)
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] );