how can I get the first part of ID from the following string?
sText ='DefId #AnyId #MyId';
sText = sText.replace(/ #.*$/g, '');
alert(sText);
The result should be as follows: "DefId #AnyId "
Many thanks in advance.
how can I get the first part of ID from the following string?
sText ='DefId #AnyId #MyId';
sText = sText.replace(/ #.*$/g, '');
alert(sText);
The result should be as follows: "DefId #AnyId "
Many thanks in advance.
You could use this regex,
(.*)#.*?$
JS code,
> var sText ='DefId #AnyId #MyId';
undefined
> sText = sText.replace(/(.*)#.*?$/g, '$1');
'DefId #AnyId '
If you don't want any space after #AnyId, then run the below regex to remove that space.
> sText = sText.replace(/(.*) #.*?$/g, '$1');
'DefId #AnyId'