Posted in Uncategorized

[Java] Regular Express for URLs detection in a sentence.


Regular Express is very great. It helps us a lot in cases of filtering string which we expect. In this section, I want to introduce once case using Regex, that is detecting URL links in a sentence.

To detect valid URLs which start with “www.”, “http” and “https” in a sentence, you can use below Regular Express:

public List<String> extractUrls(String text)
List<String> containedUrls = new ArrayList<String>();

// String urlRegex = “((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)”;
String urlRegex =
+ “(”
+ “((https?|ftp|gopher|telnet|file):((//)|(\\\\)))” // URLs starting with http://, https://, or ftp://
+ “|”
+ “(^|[^\\/])(www\\.)” // URLs starting with “www.” (without // before it, or it’d re-link the ones done above).
+ “)”
+ “+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*”
+ “)”;
Pattern pattern = Pattern.compile(urlRegex, Pattern.CASE_INSENSITIVE);

Matcher urlMatcher = pattern.matcher(text);
while (urlMatcher.find())

return containedUrls;

Above Regular Express only detect which word contain URL(s) such as: “<<>>>aaa”, etc. So, to remove unexpected other words, you can modify code to do that.

Please refer my_demo to remove unexpected words after filtering using Regular Express


Hope it help 🙂

Posted in JavaScript

[Javascript] Regular Express for URL and Email detection in a sentence.


There are many ways to detect URL(s) in a sentence:

  • Use validUrl lib: Refer detail at here

This lib has a disadvantage that is it can analyze a URL is valid or not. It means if you put that URL in a sentence such as “Hello site !”, it cannot detect the URL

  • Use below Regular Express:
function linkify(inputText) {
    var replacedText, replacePattern1, replacePattern2, replacePattern3;

    //URLs starting with http://, https://, or ftp://
    replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
    replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');

    //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
    replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
    replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');

    //Change email addresses to mailto:: links.
    replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
    replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

    return replacedText;

Using above Regular Express, you can detect URL(s) as well as Email(s) in a sentence. You can modify this Regular Express for your jobs :).

You can refer detail of Regular Express guide at here

Like and Share if it is helpful 🙂

Posted in Cordova/PhoneGap

[Cordova] Display Onsen UI popover as dropdown

It is very easy to display an Onsen UI popover as dropdown.

For full example, please refer here

Below is detail of code to display popover using Onsen UI

  • HTML
<body ng-controller="DropdownController">
Dropdown example
</ons-toolbar> </ons-page> <ons-template id="popover.html"> <ons-popover cancelable direction="down"> <ons-list> <ons-list-item ng-repeat="option in options" modifier="tappable"> {{ option }} </ons-list-item> </ons-list> </ons-popover> </ons-template> </body>
  • JS
.controller('DropdownController', function($scope) {
  ons.ready(function() {
    ons.createPopover('popover.html').then(function(popover) {
      $scope.popover = popover;

  $scope.options = ['Load', 'Sync', 'Settings'];
Posted in Mobile_Tips, Useful Apps

[App] JLT Free – Mobile app provide a huge of Japanese tests for learners



JLT – Japanese Language Test is a Mobile application which provide a lot of Test data for learner on N1, N2, N3, N4, N5 levels.

–          It is FREE

–          Easy to use, UI is very friendly.

–          It provice a lot of Japanese tests.

–          Test Result Analysis is clear.

–          Daily update.

How to download for Android ?

–          Way 1: Open “Google Play” on your mobile and search “JLT Free”, then install it.

–          Way 2: Get it from link:

Posted in Uncategorized

[Cordova] How to preview PDF file inside Cordova project


Hi all, I faced this challenge for my tasks list. After searching a lot on Internet with various solutions:

  • Using InAppBrower: this plugin can open PDF for preview but it will open a certain PDF reader application on device not inside our Cordova project
  • PDFObject: hmmm, I tried use it but I faced compile error about import it into my project, I did not fix that issue because of time limitation.

Finally, I found the solution which solved my challenge 🙂 (it saved my life 🙂 ).

Below is result:


About the detail, please follow steps of the “example” at my github

I preferred that solution at sayanee’s github. Thank him very much 🙂

You also install that plugin by npm (Ref detail at here):

npm install angular-pdf

Hope it is helpful 🙂

Posted in Cordova/PhoneGap

[Cordova] How to download a file


To download a file from given URL, we need the cordova-plugin-file-transfer plugin. You also install this plugin by command:

cordova plugin add cordova-plugin-file-transfer

Then, use below code:

 function downloadFile(downloadedFileName, downloadLink) {

var fileURL;
if (monaca.isAndroid === true) {
var androidDownloadPath = ‘/storage/emulated/0/path/to/’;
fileURL = androidDownloadPath + downloadedFileName;
} else {
var iosDownloadPath = cordova.file.documentsDirectory;
fileURL = iosDownloadPath + downloadedFileName;
var uri = encodeURI(downloadLink);
processDownloadFile(uri, fileURL);


function processDownloadFile(uri, fileURL) {
var encodedFileURL = encodeURI(fileURL);
var fileTransfer = new FileTransfer();
function(entry) {
console.log(“Download complete ! Place of downloaded file: ” + entry.toURL() + ” – Source: ” + uri);
function(error) {
console.error(“error source ” + error.source + ” – download error target ” + + ” – upload error code” + error.code);
false, {
headers: {
“Authorization”: “Basic false headers”

Posted in Android Programming, Cordova/PhoneGap, iOS Programming, Mobile_Tips

[Cordova] Tips: How to delete a file


Actually, it is very easy and simple because you can use the cordova-plugin-file

You can download the file plugin with command:

cordova plugin add cordova-plugin-file

Demo code:

var path = "file:///storage/emulated/0";
var filename = "myfile.txt";

window.resolveLocalFileSystemURL(path, function(dir) {
	dir.getFile(filename, {create:false}, function(fileEntry) {
                  // The file has been removed succesfully
                  // Error deleting the file
                 // The file doesn't exist

Hope it is useful🙂