Category Archives: Javascript

Javascript App for Modal

 

Line break from PHP to Javascript

 

Draw on Image using canvas

 

Clone a HTML element with jquery clone()

Reference:

  1. https://stackoverflow.com/questions/32637674/jquery-clone-date-picker-not-working

moment.js

 

Ajax Example

 

Calculate string length by bytes

“中文”.length in javascript will return 2 which is not the result I want, here is the replacement:

byteLength(‘中文’); will return 6.

每個中文字算2個字

Reference:

Javascript app object

 

Advanced Regular Expression

String:

Ventilator Set:\n FiO2 ≤ 40%\nDrug use:\n NO\nWeaning trials:\n NO\nStop reason:\n neurologic factors\n備註:\n

Purpose

Find the second \n and replace it with another character

Solution

https://regex101.com/r/t9gozM/1

Pattern Explanation: 在\n後面找一個最近的\n或是結尾之間的字串

Notes:

  • (?:)
    括號裡面的內容不產生指標($1之類的)
  • ^
    一行的開始
  • $
    一行的結束
  • (?=p)
    正前向聲明,要求接下來的字元都與樣式p相符,但是不包括比對中的那些字元
  • (?!p)
    反前向聲明,要求接下來的字元不與樣式p相符
  • 重複字元(如*)後加上? – 非貪婪的重複比對
    /a+/
    /a+?/ -> 只符合一個以上的字母a