Skip to content

Regex Error in JS  #1095

@sharjeelyunus

Description

@sharjeelyunus

I'm getting HTML from the server, I just need 2 IDs from it, so wrote a JS function to extract these IDs from the HTML, but it's not working in our editor. tried this in the Chrome console and it is working fine

function extractIds(htmlString) {
    var propertyIdMatch = htmlString.match(/property\/([^\/]+)\/manage/);
    var bookingIdMatch = htmlString.match(/booking=([^"\']+)/);

    var propertyId = propertyIdMatch ? propertyIdMatch[1] : null;
    var bookingId = bookingIdMatch ? bookingIdMatch[1] : null;

    return {
        propertyId: propertyId,
        bookingId: bookingId
    };
  }

var htmlString = '<html><head></head><body>Sharjeel modified the trip. <a data-ios-target="booking:05a1ead9-cf90-4bcf-8e56-0c469ffa7f4e" data-ios-target-v1="internal:booking:05a1ead9-cf90-4bcf-8e56-0c469ffa7f4e" href="https://myplace.co/app/property/831c18d1-3557-4106-9247-932a4a5c416c/manage?booking=05a1ead9-cf90-4bcf-8e56-0c469ffa7f4e">Review</a></body></html>';

var ids = extractIds(htmlString);

console.log('Property ID:', ids.propertyId);
console.log('Booking ID:', ids.bookingId);

Getting this error:

Error :  Line: 1029 in YAML and Line: 105 within the code block. Error Message: Error while executing method: htmlString.match(/property\/([^\/]+)\/manage/). Underlying error:FormatException: Illegal RegExp pattern (SyntaxError: Invalid regular expression: /property\([^\]+)\manage/: Unterminated character class)
property\([^\]+)\manage
StackTrace :  null
Line: 1029 in YAML and Line: 105 within the code block. Error Message: Error while executing method: htmlString.match(/property\/([^\/]+)\/manage/). Underlying error:FormatException: Illegal RegExp pattern (SyntaxError: Invalid regular expression: /property\([^\]+)\manage/: Unterminated character class)
property\([^\]+)\manage

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Released

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions