Manually read it from the string
For example, in "https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e" just read the last 64 characters. Tx-Codes are always 64 characters long.
Regular Expressions
If you have multiple services/websites from which you want to read the Tx-Id, you can save the position where the Tx-Id starts in the string and then read 64 characters from there. Since you did not say which programming language you want to use, I'll show an example in C++:
#include <iostream>
#include <string>
#include <vector>
#include <regex>
using namespace std;
struct PositionInString
{
PositionInString(string h, unsigned int p) : host(h), position(p) {}
string host;
unsigned int position;
};
int main()
{
vector<PositionInString> positions;
positions.push_back(PositionInString("blockchain.info", 27));
positions.push_back(PositionInString("btc.blockr.io", 30));
while(true)
{
string url;
cout << "Enter url: ";
cin >> url;
regex reg_ex("([a-z0-9|-]+\\.)*[a-z0-9|-]+\\.[a-z]+");
smatch match;
string extract;
if (regex_search(url, match, reg_ex))
{
extract = match[0];
}
else
{
cout << "Could not extract." << endl;
continue;
}
bool found = false;
for(auto& v : positions)
{
if(v.host.compare(extract) == 0)
{
cout << "Tx-Id: " << url.substr(v.position, 64) << endl;
found = true;
break;
}
}
if(found == false)
cout << "Unknown host \"" << extract << "\"" << endl;
}
return 0;
}
Output:
Enter url: https://blockchain.info/tx/a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e
Tx-Id: a97aaf679880e079f80ddca53044b8cb3bd511014fb09bd28e33d5430dab4c8e