0

I'm trying to grab just the id number from a Facebook picture URL using the replaceall regex method in Dart. What should I be using instead of $2 in the following code? The id number I need is between the "asid=" and "&height".

void main() {
 String faceavatar = 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10153806530149154&height=50&width=50&ext=1596623207&hash=AeSi1yDvk8TCqZql';
      String currentavatar = faceavatar.replaceAll(RegExp('(.*asid=)(\d*)height.*'), $2;
  print(currentavatar);
}
0

2 Answers 2

5

You may try:

.*?\basid\b=(\d+).*

Explanation of the above regex:

  • .*? - Lazily matches everything except new-line before asid.
  • \basid\b - Matches asid literally. \b represents word boundary.
  • = - Matches = literally.
  • (\d+) - Represents first capturing group matching digits one or more times.
  • .* - Greedily everything except new-line zero or more times.
  • $1 - For the replacement part you can use $1 or match.group(1).

Pictorial Representation

You can find the demo of above regex in here.

Sample Implementation in dart:

void main() {
 String faceavatar = 'https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10153806530149154&height=50&width=50&ext=1596623207&hash=AeSi1yDvk8TCqZql';
      String currentavatar = faceavatar.replaceAllMapped(RegExp(r'.*?\basid\b=(\d+).*'), (match) {
  return '${match.group(1)}';
});
  print(currentavatar);
}

You can find the sample run of the above implementation in here.

Sign up to request clarification or add additional context in comments.

Comments

-1

just getting the asid:

(?<=(asid=))(\w|\d|\n|[().,\-:;@#$%^&*\[\]"'+–/\/®°⁰!?{}|]| )+?(?=(&height))

output: 10153806530149154

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.