regex - Regular expression to extract text between two sets of characters (Javascript) - Stack Overflow

I would like to extract some text between two points in a string, in JavascriptSay the string is"s

I would like to extract some text between two points in a string, in Javascript

Say the string is

"start-extractThis-234"

The numbers at the end can be any number, but the hyphens are always present.

Ideally I think capturing between the two hypens should be ok.

I would like the result of the regex to be

extractThis

I would like to extract some text between two points in a string, in Javascript

Say the string is

"start-extractThis-234"

The numbers at the end can be any number, but the hyphens are always present.

Ideally I think capturing between the two hypens should be ok.

I would like the result of the regex to be

extractThis
Share Improve this question edited Apr 22, 2010 at 15:14 SilentGhost 320k67 gold badges310 silver badges294 bronze badges asked Apr 22, 2010 at 15:11 Chris BarryChris Barry 4,5947 gold badges57 silver badges90 bronze badges 1
  • Wow, I wonder how many of my old questions I'll be embarrised about like this one! – Chris Barry Commented Aug 18, 2012 at 10:23
Add a ment  | 

3 Answers 3

Reset to default 4
string = "start-extractThis-234"

console.log( string.match( '-(.*)-' )[1] );

//returns extractThis

why not just do

var toExtract = "start-extractThis-234";
var extracted = null;
var split = toExtract.split("-");
if(split.length === 3){
   extracted = split[1];
}
^.+?-(.+?)-\d+$

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744698715a4588650.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信